-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
59 lines (44 loc) · 1.35 KB
/
server.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
var config = require('./config');
// they recommend newrelic require to be at the top of the file
if ( config.isProduction ){
require('newrelic');
}
var cluster = require('cluster');
var forky = require('forky');
var rollbar = require('rollbar');
require('./db/cache').autoFetchFromRedis( require('./db') );
process.on('uncaughtException', function(err) {
console.log('Uncaught Exception', err, err.stack);
if (cluster.isWorker) {
forky.disconnect();
}
});
process.on('unhandledRejection', function(err) {
console.log('Unhandled Rejection', err, err.stack);
if (cluster.isWorker) {
forky.disconnect();
}
});
if (config.rollbar) {
rollbar.init(config.rollbar.accessToken, {environment: config.env});
rollbar.handleUncaughtExceptions();
}
var app = require('./app')
, http = require('http');
require('./lib/events');
require('./lib/order-notifications');
var server = http.createServer(app);
server.listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
if ( cluster.worker ){
cluster.worker.once( 'disconnect', function(){
// Timeout until we forcefully exit the process
var exitTimeout = setTimeout( process.exit.bind( process ), 10000 );
server.once( 'close', function(){
clearTimeout( exitTimeout );
process.exit();
});
});
}
module.exports = server;