-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·56 lines (47 loc) · 1.57 KB
/
server.js
File metadata and controls
executable file
·56 lines (47 loc) · 1.57 KB
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
'use strict';
module.exports = function (params, callback) {
require('config/init')();
require('config/newrelic');
const config = require('config/config');
const log = require('config/log')(module);
const socket = require('app/lib/middleware/socket-io');
// require mongoose (connect to DB)
require('config/mongoose');
require('config/consumer');
/**
* Main application entry file.
* Please note that the order of loading is important.
*/
const app = require('config/express')();
// Bootstrap script
log.info('Running bootstrap script...');
require('config/bootstrap')(app, (err) => {
if (err) {
log.error(`Bootstrap script failed with error: ${err.message}`);
callback && callback(err);
return;
}
log.info('Bootstrap script completed');
const http = require('http').createServer(app);
const io = require('socket.io')(http, { cookie: false });
const redisAdapter = require('socket.io-redis');
io.adapter(redisAdapter({
host: config.redis.host,
port: config.redis.port,
password: config.redis.password,
}));
io.set('transports', ['websocket']);
io.timeStamp = new Date();
socket.initSocketIo(io, app);
// Start the app by listening on <port>
http.listen(config.port);
app.io = io;
// Logging initialization
log.info(`"${config.app.title}" application started on port ${config.port}`);
callback && callback(null, app);
});
process.on('uncaughtException', (err) => {
log.error(`Unhandled exception raised: ${err}`);
callback && callback(err);
});
};