-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
37 lines (31 loc) · 1.04 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
/**
* Created by sbanas on 14.04.2017.
*/
'use strict';
const _ = require('lodash');
const yamlConfig = require('yaml-config');
const App = require('./src/app');
const LogProvider = require('./src/log-provider');
// Load configuration
const argv = require('minimist')(process.argv.slice(2));
const configFile = _.defaultTo(argv.config, './config.yml');
const env = _.defaultTo(argv.env, process.env.NODE_ENV);
// Initialize
const config = yamlConfig.readConfig(configFile, env);
const logProvider = new LogProvider(config.logger);
const logger = logProvider.get();
logger.info('Starting for environment \'%s\'', env);
logger.info('Loading config from \'%s\'', configFile);
const app = new App(config, logProvider);
app.run();
logger.info('Started.');
process.on("uncaughtException", function (err) {
logger.error((new Date).toUTCString() + " Uncaught exception...");
logger.error(err.message);
logger.error(err.stack);
process.exit(1);
});
process.once("SIGTERM", function () {
logger.info("Kill signal received...");
app.stop();
});