forked from linagora/hublin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
37 lines (33 loc) · 1.03 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
const async = require('async');
const moduleManager = require('./backend/module-manager');
const core = require('./backend/core');
const logger = core.logger;
const { modules } = core.config('default');
function setupServerEnvironment(callback) {
moduleManager.setupServerEnvironment().then(() => callback(), callback);
}
function fireAppState(state) {
return function fireApp(callback) {
moduleManager.manager.fire(state, modules).then(() => callback(), callback);
};
}
function initCore(callback) {
core.init(err => {
if (!err) {
/*eslint no-process-env: 0*/
logger.info(`Hublin core bootstraped, configured in ${process.env.NODE_ENV} mode`);
}
callback(err);
});
}
async.series([setupServerEnvironment, fireAppState('lib'), initCore, fireAppState('start')], err => {
if (err) {
logger.error('Fatal error:', err);
if (err.stack) {
logger.error(err.stack);
}
/*eslint no-process-exit: 0*/
process.exit(1);
}
logger.info(`Hublin is now started on node ${process.version}`);
});