-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
54 lines (45 loc) · 1.15 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const path = require('path');
const Application = require('./server/app').Application;
const defaultConfigFile = `${__dirname}/config/default.json`;
/**
* Envionment based config file.
*
* Matches `./config/${ENVIRONMENT}.json`
*
* $ set -lx ENVIRONMENT uat; node server
*/
const shouldUseEnvVarConfigFile = !!process.env.ENVIRONMENT;
/**
* Argument based config file.
*
* Matches `./config/${--config= <something> }.json`
*
* $ node server --config=uat
*/
const shouldUseArgConfigFile = process.argv.some(val => /--config/.test(val));
const configPath = () => {
switch (true) {
case shouldUseArgConfigFile:
return path.join(
__dirname,
'config',
process.argv
.filter(val => /--config/.test(val))
.map(val => val.split('=')[1])[0]
);
case shouldUseEnvVarConfigFile:
return path.join(
__dirname,
'config',
process.env.ENVIRONMENT.toLowerCase() + '.json'
);
default:
return defaultConfigFile;
}
};
const config = require('./server/configResolver')(path.normalize(configPath()));
const FoxApp = new Application(config);
FoxApp.start();
if (config.eureka) {
require('./server/eureka').start(config);
}