-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (44 loc) · 1.52 KB
/
index.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
var path = require('path');
module.exports = {
start: function(envPath) {
require('dotenv').config({ path: envPath });
var SocketCluster = require('socketcluster').SocketCluster;
var db = require(path.normalize(__dirname + '/db'));
var config = require(path.normalize(__dirname + '/config'));
var onlineUsers = require(path.normalize(__dirname + '/plugins/online'));
return db.users.testConnection()
.then(onlineUsers.logOptions)
.then(onlineUsers.clear)
.then(function() {
return new Promise(function(resolve) {
var socketCluster = new SocketCluster({
authKey: config.authKey,
workers: config.workers,
brokers: config.brokers,
wsEngine: config.wsEngine,
protocol: config.protocol,
protocolOptions: config.protocolOptions,
port: config.port,
host: config.host,
appName: 'ept-ws',
workerController: path.normalize(__dirname + '/worker.js'),
allowClientPublish: false
});
return resolve(socketCluster);
})
// cleanup (process exit, flushes db)
.then(function() {
function exit(options, err) {
if (err) { console.log(err); }
console.log('[WSS] Flushing Online Users');
return onlineUsers.clear()
.then(function() { process.exit(); });
}
process.on('exit', exit);
process.on('SIGINT', exit);
process.on('uncaughtException', exit);
});
})
.catch(console.log);
}
};