-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
103 lines (103 loc) · 3.67 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const pomelo = require("pomelo");
const fs = require("fs");
const path = require("path");
const routeUtil_1 = require("./app/utils/routeUtil");
const accountService_1 = require("./app/services/accountService");
const webserver_1 = require("./webserver");
process.on("uncaughtException", (err) => {
console.error(" Caught exception: " + err.stack);
});
const config_1 = require("./config/config");
/**
* Logging database.
*/
const DbClient_1 = require("./app/DbClient");
DbClient_1.InitDatabaseConnection(config_1.DBConfig.database_name).then(db => {
db.stats().then(stat => {
console.log("api status ready.", stat.db);
}).catch(err => {
console.warn("Cannot get db state!", err);
});
}).catch(err => {
console.warn("Cannot connect database", err);
});
/**
* Init app for client.
*/
const app = pomelo.createApp();
app.set("name", process.env.npm_package_name);
// app configure
app.configure("development", () => {
// filter configures
// app.before(pomelo.filters.toobusy(100));
// app.filter(pomelo.filters.serial(5000));
// route configures
app.route("chat", routeUtil_1.default);
app.set("accountService", new accountService_1.AccountService(app));
// app.set('pushSchedulerConfig', { scheduler: pomelo.pushSchedulers.buffer});
app.set("connectorConfig", {
connector: pomelo.connectors.hybridconnector,
// connector: pomelo.connectors.sioconnector,
transports: ["websocket"],
heartbeatTimeout: 60,
heartbeatInterval: 25,
});
// @ require monitor in pomelo@2x
// app.set('monitorConfig',
// {
// monitor : pomelo.monitors.zookeepermonitor,
// servers: "git.animation-genius.com:2181"
// });
});
app.configure("production", () => {
// filter configures
// app.before(pomelo.filters.toobusy(100));
// app.filter(pomelo.filters.serial(5000));
// route configures
app.route("chat", routeUtil_1.default);
app.set("accountService", new accountService_1.AccountService(app));
// app.set('pushSchedulerConfig', { scheduler: pomelo.pushSchedulers.buffer});
// let certsFolder = path.join(__dirname, "/certs");
// fs.readdirSync(certsFolder).forEach(file => {
// console.log(file);
// });
const privateKey = path.join("/etc/letsencrypt/live/chitchats.ga", "/privkey.pem");
const cert = path.join("/etc/letsencrypt/live/chitchats.ga", "/cert.pem");
const chain = path.join("/etc/letsencrypt/live/chitchats.ga", "/chain.pem");
const options = {
cert: fs.readFileSync(cert),
key: fs.readFileSync(privateKey),
// This is necessary only if using the client certificate authentication.
// requestCert: true,
ca: [fs.readFileSync(chain)],
};
app.set("connectorConfig", {
connector: pomelo.connectors.hybridconnector,
// connector: pomelo.connectors.sioconnector,
transports: ["websocket"],
heartbeatTimeout: 60,
heartbeatInterval: 25,
ssl: options,
});
// @ require monitor in pomelo@2x
// app.set('monitorConfig',
// {
// monitor : pomelo.monitors.zookeepermonitor,
// servers: "git.animation-genius.com:2181"
// });
});
// Configure for auth server
app.configure("production|development", "auth", () => {
console.log("start auth server");
});
app.configure("production|development", "chat", () => {
console.log("start chat server");
});
app.configure("production|development", "master", () => {
console.log("start master server");
webserver_1.default(app);
});
// start app
app.start();