-
Notifications
You must be signed in to change notification settings - Fork 7
/
config.js
79 lines (65 loc) · 1.63 KB
/
config.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const convict = require('convict');
const path = require('path');
convict.addFormat({
name: 'strings-array',
validate: val => {
if (!Array.isArray(val) || val.some(v => typeof v !== 'string')) {
throw new Error('must be an array of strings');
}
},
coerce: val => val.split(',').map(v => v.trim()).filter(v => v !== ''),
});
const config = convict({
env: {
doc: 'The application environment.',
format: ['production', 'development', 'test'],
default: 'development',
env: 'NODE_ENV',
},
config: {
doc: 'Custom config file to load',
format: String,
default: '',
arg: 'config',
},
logLevel: {
doc: 'Logging level',
format: ['trace', 'verbose', 'debug', 'info', 'warn', 'error', 'critical'],
default: 'info',
},
port: {
doc: '',
format: 'port',
default: 3000,
env: 'BOOBEN_PORT',
},
serveStatic: {
doc: '',
format: Boolean,
default: false,
env: 'BOOBEN_SERVE_STATIC',
},
projectsDir: {
doc: 'Projects directory. Default value is for Docker build.',
format: String,
default: '/var/lib/booben/projects',
env: 'BOOBEN_PROJECTS_DIR',
},
defaultComponentLibs: {
doc: '',
format: 'strings-array',
default: [],
env: 'BOOBEN_DEFAULT_COMPONENT_LIBS',
},
});
// Load environment dependent configuration
const env = config.get('env');
config.loadFile(path.join(__dirname, 'config', `${env}.json`));
// Load custom config file
const customConfigFile = config.get('config');
if (customConfigFile) config.loadFile(customConfigFile);
// Perform validation
config.validate({
strict: true,
});
module.exports = config;