Created
May 6, 2012 20:44
-
-
Save sandfox/2624302 to your computer and use it in GitHub Desktop.
lukes http server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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