1 | require('./eventBus');
|
2 |
|
3 | const pluginsLoader = require('./plugins');
|
4 | if (require.main === module) {
|
5 | const config = require('./config');
|
6 | const plugins = pluginsLoader.load({ config });
|
7 | require('./gateway')({ plugins, config });
|
8 | require('./rest')({ plugins, config });
|
9 | } else {
|
10 | class Main {
|
11 | constructor () {
|
12 | this.configPath = null;
|
13 | }
|
14 |
|
15 | load (configPath) {
|
16 | this.configPath = configPath;
|
17 | return this;
|
18 | }
|
19 |
|
20 | run () {
|
21 | process.env.EG_CONFIG_DIR = this.configPath || process.env.EG_CONFIG_DIR;
|
22 | const config = require('./config');
|
23 | const plugins = pluginsLoader.load({ config });
|
24 | const gateway = require('./gateway')({ plugins, config });
|
25 | const admin = require('./rest')({ plugins, config });
|
26 |
|
27 | return Promise.all([gateway, admin]);
|
28 | }
|
29 | }
|
30 |
|
31 | module.exports = () => {
|
32 | return new Main();
|
33 | };
|
34 | }
|