-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
43 lines (37 loc) · 1.06 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
39
40
41
42
43
/*
* Main module which handles application backend.
*/
'use strict';
let logger = require('./server/middleware/winston'),
db = require('./server/lib/db'),
app = require('./server/lib/app'),
batch = require('./server/lib/schedule');
global.logger = logger;
let task;
// main function
async function main() {
//Setup the application server start up tasks
try {
await db.connectToMongo();
await app.serveApplication();
await db.setupDb();
// Setup the batch job to update flight records daily
// task = await batch.schedule();
// await task.start();
await logger.info('Application ready in ....' + process.env.NODE_ENV);
} catch (err) {
await logger.error('Failed to start application....');
await handleShutDown();
}
}
// handle error on startup
async function handleShutDown() {
await db.closeConnection();
await setTimeout(() => process.exit(500));
if (task) await task.stop();
}
// handle shutdown
process.on('SIGINT', () => handleShutDown());
//start application, handle error on startup
main();
module.exports = app;