2022-02-07 15:41:27 +01:00
|
|
|
const logger = require('./libs/logger.js');
|
|
|
|
const api = require('./libs/api.js');
|
|
|
|
const server = require('./libs/server.js')
|
2022-02-20 22:04:32 +01:00
|
|
|
const util = require('./libs/util.js');
|
2022-02-07 15:41:27 +01:00
|
|
|
const packageJSON = require('./package.json');
|
|
|
|
|
2022-02-20 22:04:32 +01:00
|
|
|
const INTERRUPTS = ['SIGINT', 'SIGTERM'];
|
|
|
|
|
|
|
|
global.config = process.argv[2] || __dirname + '/config.json';
|
|
|
|
|
|
|
|
handleInterrupts();
|
|
|
|
|
|
|
|
util.fileExists(config)
|
|
|
|
.then((result) => {
|
|
|
|
global.config = require(result.path);
|
|
|
|
global.config.path = result.path;
|
|
|
|
})
|
|
|
|
.then(logger.initialize)
|
|
|
|
.then(() => {
|
|
|
|
logger.info("launching " + packageJSON.name + " " + packageJSON.version);
|
|
|
|
})
|
|
|
|
.then(api.setupEndpoints)
|
2022-02-07 15:41:27 +01:00
|
|
|
.then(server.start)
|
2022-02-20 22:04:32 +01:00
|
|
|
.catch((err) => {
|
2022-02-07 15:41:27 +01:00
|
|
|
logger.error(err);
|
|
|
|
process.exit(1);
|
2022-02-20 22:04:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
function handleInterrupts() {
|
|
|
|
for (var index = 0; index < INTERRUPTS.length; index++) {
|
|
|
|
process.once(INTERRUPTS[index], (code) => {
|
|
|
|
watchers.stop()
|
|
|
|
.then(exit(code))
|
|
|
|
.catch(exit(code));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|