-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
48 lines (39 loc) · 1.09 KB
/
config.js
File metadata and controls
48 lines (39 loc) · 1.09 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
/**
* Created by steven on 17/5/5.
*/
const path = require('path');
const fs = require('fs');
const vm = require('vm');
let config = {};
const configPath = path.join(__dirname, './config_master.js');
config.mongodb = {
url: 'mongodb://10.0.15.70:27017/ump_v1',
dbInstance: null
};
config.KEY = 'secret';
config.cookieExpires = 1000 * 60 * 60 * 24 * 7;
config.port = process.env.NODE_ENV === 'development' ? 8080 : 8080;
let readConfig = function(p) {
const sandbox = {
path: path,
config: config,
__dirname: __dirname,
console: console,
process: process
};
vm.createContext(sandbox);
vm.runInContext(fs.readFileSync(p), sandbox);
};
if(fs.existsSync(configPath)) {
//读取生产环境config_master.js文件
readConfig(configPath);
}else {
if (process.env.NODE_ENV == 'development') { //本地开发环境
readConfig(path.join(__dirname, './config_master.js'));
config.host = "localhost:8000";
config.domain = 'http://' + config.host;
}else {
throw new Error('******** config_master.js file is not exist ********');
}
};
module.exports = config;