1 var http = require('http'),
2 httpProxy = require('../../lib/node-http-proxy');
5 // A simple round-robin load balancing strategy.
7 // First, list the servers you want to use in your rotation.
21 // Create a HttpProxy object for each target
24 var proxies = addresses.map(function (target) {
25 return new httpProxy.HttpProxy({
31 // Get the proxy at the front of the array, put it at the end and return it
32 // If you want a fancier balancer, put your code here
35 function nextProxy() {
36 var proxy = proxies.shift();
42 // Get the 'next' proxy and send the http request
45 var server = http.createServer(function (req, res) {
46 nextProxy().proxyRequest(req, res);
50 // Get the 'next' proxy and send the upgrade request
53 server.on('upgrade', function (req, socket, head) {
54 nextProxy().proxyWebSocketRequest(req, socket, head);