-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (32 loc) · 983 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
require('./require');
const { config, routes } = global;
const { async, express, notify } = global;
// terminate
process.once('SIGINT', () => shutdown('SIGINT'));
process.once('SIGTERM', () => shutdown('SIGTERM'));
// starting
async.auto({
http: (cb) => {
const app = express();
const router = routes.init();
app.use(router);
app.listen(config.web_port, config.web_host, () => {
console.debug(`[+] init http://${config.web_host}:${config.web_port}${config.web_key}`);
cb();
});
}
}, (e) => {
if (e) {
console.error('[-] FATAL, service can\'t start');
// console.log(e);
notify(`#error #${global.config.project} FATAL, service can't start: ${e.message || e}`);
setTimeout(() => { shutdown('errOnStart'); }, 3000);
return;
}
console.log('[+] service started');
});
// ==============================================
function shutdown(signal) {
console.info(`[x] ${signal} signal received`);
process.exit(0);
}