-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.js
executable file
·66 lines (56 loc) · 1.65 KB
/
main.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
#!/usr/bin/env node
/*
Inspiration taken from
https://github.com/jupyter/multiuser-server/blob/master/multiuser/js/main.js
*/
const args = require("commander");
const packageInfo = require("../package");
const { DynamicProxy } = require("./proxy");
const { mapFor } = require("./mapper");
args
.version(packageInfo.version)
.option("--ip <n>", "Public-facing IP of the proxy", "localhost")
.option("--port <n>", "Public-facing port of the proxy", parseInt)
.option("--sessions <file>", "Routes file to monitor")
.option("--proxyPathPrefix <path>", "Path-based proxy prefix")
.option("--forwardIP <n>", "Forward all requests to IP")
.option("--forwardPort <n>", "Forward all requests to port", parseInt)
.option(
"--reverseProxy",
"Cause the proxy to rewrite location blocks with its own port",
)
.option("--verbose");
const main = function (argv_) {
const argv = argv_ || process.argv;
args.parse(argv);
let sessions = null;
if (args.sessions) {
sessions = mapFor(args.sessions);
}
const dynamicProxyOptions = {
sessionMap: sessions,
proxyPathPrefix: args.proxyPathPrefix,
verbose: args.verbose,
port: args.port,
};
if (args.reverseProxy) {
dynamicProxyOptions.reverseProxy = true;
}
if (args.forwardIP) {
dynamicProxyOptions.forwardIP = args["forwardIP"];
}
if (args.forwardPort) {
dynamicProxyOptions.forwardPort = args["forwardPort"];
}
const dynamicProxy = new DynamicProxy(dynamicProxyOptions);
const listen = {
port: args.port || 8000,
ip: args.ip,
};
dynamicProxy.listen(listen);
return dynamicProxy;
};
exports.main = main;
if (require.main === module) {
main();
}