-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (42 loc) · 897 Bytes
/
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
49
50
51
52
53
54
'use strict';
const datastore = require('./services/datastore');
const webServer = require('./bin/web-server');
const debug = require('debug')('index');
debug('Starting application.');
(async function () {
try {
await datastore.connect();
await webServer.start();
} catch (err) {
debug('Encountered error', err);
process.exit(1);
}
})();
process.on('uncaughtException', err => {
debug('Uncaught exception', err);
shutdown(err);
});
process.on('SIGTERM', () => {
debug('Received SIGTERM');
shutdown();
});
process.on('SIGINT', () => {
debug('\nReceived SIGINT');
shutdown();
});
async function shutdown(e) {
let err = e;
debug('Shutting down ...');
try {
debug('Stopping web server ...');
await webServer.stop();
} catch (e) {
debug('Encountered error', e);
err = err || e;
}
debug('Exiting process');
if (err) {
process.exit(1);
}
process.exit(0);
}