-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
50 lines (40 loc) · 1.19 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
/**
* Copyright 2017–2018, LaborX PTY
* Licensed under the AGPL Version 3 license.
* @author Egor Zuev <zyev.egor@gmail.com>
*/
/**
* Expose an express web server
* @module middleware-custom-service
*/
const config = require('./config'),
mongoose = require('mongoose'),
Promise = require('bluebird'),
path = require('path'),
bunyan = require('bunyan'),
migrator = require('middleware_service.sdk').migrator,
_ = require('lodash'),
log = bunyan.createLogger({name: 'core.rest'}),
redInitter = require('middleware_service.sdk').init;
mongoose.Promise = Promise;
mongoose.mainnet = mongoose.createConnection(config.main.mongo.uri);
mongoose.sidechain = mongoose.createConnection(config.sidechain.mongo.uri);
[mongoose.sidechain, mongoose.mainnet].forEach(instance =>
instance.on('disconnected', function () {
log.error('mongo disconnected!');
process.exit(0);
})
);
const init = async () => {
require('require-all')({
dirname: path.join(__dirname, '/models'),
filter: /(.+Model)\.js$/
});
if (config.nodered.autoSyncMigrations)
await migrator.run(
config,
path.join(__dirname, 'migrations')
);
redInitter(config);
};
module.exports = init();