-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
34 lines (32 loc) · 818 Bytes
/
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
'use strict';
//Load the config file.
var config = require('./config/config.json');
/*-------------------------------------------------------*/
function parseEnv(name, value, cnf) {
if (name in cnf) {
cnf[name] = value;
return;
}
var parts = name.split('_');
var pos = 0
var found = false
while (!found && pos < parts.length) {
pos = pos + 1;
var group = parts.slice(0,pos).join('_');
if (group in cnf){
found = true;
parseEnv(parts.slice(pos).join('_'), value, cnf[group]);
}
}
if (!found) {
console.log("%s not found in config", name);
}
}
// overwrite with Environment variables
for (var key in process.env) {
if (key.indexOf('RAINTANK_') == 0) {
var name = key.slice(9);
parseEnv(name, process.env[key], config);
}
}
exports.config = config;