Skip to content

Instantly share code, notes, and snippets.

@sandfox
Created May 6, 2012 20:44
Show Gist options
  • Save sandfox/2624302 to your computer and use it in GitHub Desktop.
Save sandfox/2624302 to your computer and use it in GitHub Desktop.
lukes http server
var config = {
servers: [
{ host: '192.168.33.10', port: 80 },
{ host: '192.168.33.11', port: 80 }
]
};
var http = require('http'),
httpProxy = require('http-proxy'),
numServers = config.servers.length-1,
targetServer = 0;
function getNextTarget() {
return (targetServer < numServers ? ++targetServer : targetServer = 0);
}
httpProxy.createServer(function (req, res, proxy) {
var target = getNextTarget();
proxy.proxyRequest(req, res, config.servers[ target ]);
}).listen(8000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment