Added comments

This commit is contained in:
Oscar Östlund 2012-11-25 22:26:25 -05:00 committed by indexzero
parent 83fbd42506
commit 64efa7f929

View File

@ -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);
}); });