-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
74 lines (68 loc) · 2.16 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
var fs = require('fs'),
path = require('path'),
nconfmod = require('nconf'),
_ = require('underscore');
module.exports = exports = function(overrides) {
var nconf = new nconfmod.Provider();
if (overrides)
nconf.overrides(overrides);
nconf.argv()
.env({
separator: '__',
match: /^LIVEPROXY/
});
var localConfigFile = path.resolve( nconf.get( 'localconf' ) || 'config-local.json' );
if (fs.existsSync(localConfigFile)) {
console.log("Reading local config from: " + localConfigFile);
nconf = nconf.file('local', {file: localConfigFile});
}
var defaultConfigFile = path.resolve( 'config.json' );
if (fs.existsSync(defaultConfigFile)) {
console.log("Reading config from: " + defaultConfigFile);
nconf = nconf.file('default', {file: defaultConfigFile});
}
nconf = nconf.defaults({
'inject': [],
'replace': [],
'port': 80,
'secure':false,
'ssl': false,
'suffix': "livelocal:8000",
'listen': "127.0.0.1",
'cookie_prefix': '',
'hidden_headers': [],
'proto_separator': '-',
'mask_redirect': false,
'context': {},
'targets': [ 'cookie', 'base32' ],
'redirects': {},
"error_handlers": [
'redirect'
],
'deactivateExternal': false
});
nconf.get('inject').forEach(function(i) {
if (i.file) {
var p = path.resolve(i.file);
if (!fs.existsSync(p))
throw "Can't find file: " + i.file;
console.log("reading payload file "+ p);
try {
var data = fs.readFileSync(p, 'utf8');
i.payload = _.template(data);
} catch (e) {
console.log("Error processing " + p);
console.log(e);
}
delete i.file;
} else if (i.payload) {
try {
i.payload = _.template(i.payload);
} catch (e) {
console.log("Error processing: " + i.payload);
console.log(e);
}
}
});
return nconf;
};