-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (35 loc) · 918 Bytes
/
index.js
File metadata and controls
41 lines (35 loc) · 918 Bytes
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
var request = require("request-promise"),
fs = require("fs-extra"),
args = require('minimist')(process.argv.slice(2)),
proxy
;
//console.log("Start NoInfoPath Reverse Proxy in ", platform);
function resloveConfig(path) {
if(path.indexOf("http") === 0) {
return request(path)
.then(function(results){
return JSON.parse(results);
})
.catch(function(err){
throw err;
});
} else {
if(fs.existsSync(path)) {
var config = fs.readJsonSync(path);
return Promise.resolve(config);
} else {
return Promise.reject(new Error("Configuration not found"));
}
}
}
resloveConfig(args.config)
.then(function(config){
proxy = require('redbird')(config.redbird.init);
config.redbird.proxies.forEach(function (prx) {
proxy.register(prx.source, prx.dest, prx.options);
});
})
.catch(function(err){
console.error(err);
});
//Create proxy for each item in the config.json file.