-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (46 loc) · 1.21 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict'
const path = require('path')
// globals definition
global.requireRoot = function (name) {
return require(path.resolve('src/', name))
}
// Basic includes
const debug = require('debug')('app:root')
debug('init')
// bootstrap express
const parameters = require('./parameters')
const express = require('express')
const app = express()
// AppManager
const appManager = require('./src/appManager')
// init dbs
appManager.initDBs()
appManager.once('appManager:db:ready', () => {
require('./src/middlewares')(app)
require('./src/routes')(app)
require('./src/handlers')(app)
var port = process.env.TEST_MODE
? parameters.test.listenPort
: parameters.listenPort
// If run in mocha disabled the listen
if (!process.env.TEST_MODE) {
app.listen(port, function () {
debug('App listening ', port)
})
} else {
appManager.emit('appManager:app:ready', app)
}
})
// Simple process log
process.on('exit', function () {
debug('exit')
})
process.on('SIGINT', function () {
debug('sigint')
process.exit(1)
})
process.on('uncaughtException', function (err) {
if (!process.env.TEST_MODE) {
debug('uncaughtException', err)
}
})