Skip to content

Commit

Permalink
Added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
oost authored and indexzero committed Mar 9, 2013
1 parent 83fbd42 commit 64efa7f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions examples/balancer/simple-balancer-with-websockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,39 @@ var addresses = [
}
];

//
// Create a HttpProxy object for each target
//

var proxies = addresses.map(function (target) {
return new httpProxy.HttpProxy({
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() {
var proxy = proxies.shift();
proxies.push(proxy);
return proxy;
}

//
// Get the 'next' proxy and send the http request
//

var server = http.createServer(function (req, res) {
nextProxy().proxyRequest(req, res);
});

//
// Get the 'next' proxy and send the upgrade request
//

server.on('upgrade', function(req, socket, head) {
nextProxy().proxyWebSocketRequest(req, socket, head);
});
Expand Down

0 comments on commit 64efa7f

Please sign in to comment.