-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
56 lines (53 loc) · 1.35 KB
/
config.js
File metadata and controls
56 lines (53 loc) · 1.35 KB
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
/**
* Load app configurations
*/
var fs = require('fs');
var configPath = './config.json';
var configInfo = {};
try {
fs.statSync(configPath);
} catch (e) {
fs.writeFileSync(configPath, fs.readFileSync(configPath + '.sample'));
console.log('creating config file finished');
} finally {
configInfo = JSON.parse(fs.readFileSync(configPath));
}
function getConfigProperty(key) {
var valueFormEnv = process.env[key];
if(valueFormEnv) {
return valueFormEnv;
}
return configInfo[key];
}
module.exports = {
getListeningPort: function() {
return getConfigProperty('NODE_PORT');
},
getNodeEnv: function() {
return getConfigProperty('NODE_ENV');
},
isDevMode: function() {
var env = getConfigProperty('NODE_ENV');
return 'dev' === env || 'development' === env;
},
isProdMode: function() {
var env = getConfigProperty('NODE_ENV');
return 'prod' === env || 'production' === env;
},
isNodeProxyEnabled: function() {
return !!getConfigProperty('NODE_PROXY');
},
getStaticAssetsEndpoint: function() {
//AKA, get CDN domain
return getConfigProperty('STATIC_ENDPOINT');
},
getApiEndPoints: function () {
return getConfigProperty('API_ENDPOINTS');
},
getProxyDebugLevel: function() {
return getConfigProperty('PROXY_DEBUG_LEVEL');
},
getEnv: function(key) {
return getConfigProperty(key);
}
};