-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconfig.js
More file actions
57 lines (46 loc) · 1.41 KB
/
config.js
File metadata and controls
57 lines (46 loc) · 1.41 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
57
const Path = require('path');
const ms = require('ms');
const { existsSync } = require('fs');
const { mergeObj, getArg, getFlag } = require('./utils');
const log = require('./log');
const ROOT = process.cwd();
function load (path) {
try {
return require(path);
} catch (error) {
log.error('Config loading error', error);
process.exit(-1);
}
}
let config;
let configPath = getArg('--cfg');
if (configPath) {
if (configPath[0] != '/') configPath = Path.join(ROOT, configPath);
if (!existsSync(configPath)) {
log.error('Config file not found');
process.exit(-1);
}
config = load(configPath);
} else {
configPath = require.resolve(Path.join(ROOT, 'config'));
config = existsSync(configPath) ? load(configPath) : {};
}
if (config.port === false) {
} else if (!config.port || config.port === '$env') {
config.port = config.port === '$env' ? process.env.PORT : 8081;
}
config.db = config.db || {};
config.isDev = getFlag('--dev');
if (config.isDev) {
if (config.dev) {
mergeObj(config, config.dev);
}
config.ignore = config.ignore || [];
if (!~config.ignore.indexOf('node_modules')) config.ignore.push('node_modules');
}
delete config.dev;
if (config.session) {
config.session.ttl = config.session.ttl || '3d';
if (typeof config.session.ttl == 'string') config.session.ttl = ms(config.session.ttl);
}
module.exports = config;