-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
36 lines (33 loc) · 1.22 KB
/
app.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
var argv = require("minimist")(process.argv)
, cluster = require("cluster")
, numCpus = require("os").cpus().length
, HttpProxy = require("./")
, options = {}
, port = 0
, httpProxy;
if (argv.auth) options.auth = argv.auth;
if (argv.proxy) options.proxy = argv.proxy;
if (argv.maxSockets) options.maxSockets = argv.maxSockets;
if (argv.localAddress) options.localAddress = argv.localAddress;
if (argv.followRedirect) options.followRedirect = argv.followRedirect;
if (argv.port) port = argv.port;
if (!argv.cluster) {
httpProxy = new HttpProxy(options);
return httpProxy.listen(port, function () {
console.log("Proxy server listening on %s:%d", httpProxy.server.address().address, httpProxy.server.address().port);
});
};
if (cluster.isMaster) {
for (var i = 0; i < numCpus; i++) {
cluster.fork();
};
cluster.on("exit", function(worker, code, signal) {
console.log("worked with PID %d died with code %d and signal %s. Restarting...", worker.process.pid, code, signal);
cluster.fork();
});
} else {
httpProxy = new HttpProxy(options);
httpProxy.listen(port, function () {
console.log("Proxy server listening on %s:%d", httpProxy.server.address().address, httpProxy.server.address().port);
});
};