forked from stellar-expert/operations-notifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
38 lines (31 loc) · 1.28 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
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
function init() {
const config = require('./models/config')
//init storage and persistence layer
const storage = require('./logic/storage')
return storage.init(config)
.then(() => {
//init and start observer
const observer = require('./logic/observer')
observer.start()
//setup moment formatting extension
require('moment-duration-format')(require('moment-timezone'))
//init HTTP server and map all API routes
const server = require('./api/server-initialization')(config)
//TODO: implement graceful observer finalization on OS kill signal
function shutdown() {
console.log('Received kill signal');
server.close(() => {
console.log('Closed out remaining connections');
process.exit(0);
});
setTimeout(() => {
console.error('Could not close connections in time, forcefully shutting down');
process.exit(1);
}, 10000);
}
server.shutdown = shutdown
return Promise.resolve(server)
})
}
module.exports = init()