Skip to content

Commit 64efa7f

Browse files
oostindexzero
authored andcommittedMar 9, 2013
Added comments
1 parent 83fbd42 commit 64efa7f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
 

‎examples/balancer/simple-balancer-with-websockets.js

+17
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,39 @@ var addresses = [
1515
}
1616
];
1717

18+
//
19+
// Create a HttpProxy object for each target
20+
//
21+
1822
var proxies = addresses.map(function (target) {
1923
return new httpProxy.HttpProxy({
2024
target: target
2125
});
2226
});
2327

28+
//
29+
// Get the proxy at the front of the array, put it at the end and return it
30+
// If you want a fancier balancer, put your code here
31+
//
32+
2433
function nextProxy() {
2534
var proxy = proxies.shift();
2635
proxies.push(proxy);
2736
return proxy;
2837
}
2938

39+
//
40+
// Get the 'next' proxy and send the http request
41+
//
42+
3043
var server = http.createServer(function (req, res) {
3144
nextProxy().proxyRequest(req, res);
3245
});
3346

47+
//
48+
// Get the 'next' proxy and send the upgrade request
49+
//
50+
3451
server.on('upgrade', function(req, socket, head) {
3552
nextProxy().proxyWebSocketRequest(req, socket, head);
3653
});

0 commit comments

Comments
 (0)
Please sign in to comment.