From 64efa7f9291a2377a32e942a247700b71b107993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20O=CC=88stlund?= Date: Sun, 25 Nov 2012 22:26:25 -0500 Subject: [PATCH] Added comments --- .../balancer/simple-balancer-with-websockets.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/examples/balancer/simple-balancer-with-websockets.js b/examples/balancer/simple-balancer-with-websockets.js index efa0c1c..9c039f1 100644 --- a/examples/balancer/simple-balancer-with-websockets.js +++ b/examples/balancer/simple-balancer-with-websockets.js @@ -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); });