-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (44 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
'use strict';
const { EventEmitter } = require('events');
const server = require('./server/server');
const repository = require('./repository/repo');
const config = require('./config/');
const logs = require('./logs/');
const mediator = new EventEmitter();
process.on('uncaughtException', (err, origin) => {
logs('error', err);
logs('debug', 'uncaughtException at: '+ origin);
});
process.on('unhandledRejection', (reason, promise) => {
logs('error', reason);
logs('debug', 'Unhandled rejection at: ' + promise);
});
process.on('uncaughtRejection', (err, promise) => {
logs('error', err);
logs('debug', 'uncaughtRejection at: ' + promise);
});
process.on('warning', (msg) => {
logs('debug', msg);
});
mediator.on('db.ready', (db, client) => {
repository.connect(db)
.then(repo => {
console.log('Connected, Starting server');
return server.start({
port: config.serverSettings.port,
ssl: config.serverSettings.ssl,
repo
})
.then(app => {
console.log('Server started successfully');
app.on('close', () => {
client.close();
})
})
})
});
mediator.on('db.error', (err) => {
logs('error', err);
});
config.db.connect(config.dbSettings, mediator);
mediator.emit('boot.ready');