mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
Added comments
This commit is contained in:
parent
83fbd42506
commit
64efa7f929
@ -15,22 +15,39 @@ var addresses = [
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
//
|
||||||
|
// Create a HttpProxy object for each target
|
||||||
|
//
|
||||||
|
|
||||||
var proxies = addresses.map(function (target) {
|
var proxies = addresses.map(function (target) {
|
||||||
return new httpProxy.HttpProxy({
|
return new httpProxy.HttpProxy({
|
||||||
target: target
|
target: target
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//
|
||||||
|
// Get the proxy at the front of the array, put it at the end and return it
|
||||||
|
// If you want a fancier balancer, put your code here
|
||||||
|
//
|
||||||
|
|
||||||
function nextProxy() {
|
function nextProxy() {
|
||||||
var proxy = proxies.shift();
|
var proxy = proxies.shift();
|
||||||
proxies.push(proxy);
|
proxies.push(proxy);
|
||||||
return proxy;
|
return proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Get the 'next' proxy and send the http request
|
||||||
|
//
|
||||||
|
|
||||||
var server = http.createServer(function (req, res) {
|
var server = http.createServer(function (req, res) {
|
||||||
nextProxy().proxyRequest(req, res);
|
nextProxy().proxyRequest(req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//
|
||||||
|
// Get the 'next' proxy and send the upgrade request
|
||||||
|
//
|
||||||
|
|
||||||
server.on('upgrade', function(req, socket, head) {
|
server.on('upgrade', function(req, socket, head) {
|
||||||
nextProxy().proxyWebSocketRequest(req, socket, head);
|
nextProxy().proxyWebSocketRequest(req, socket, head);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user