Skip to content

Instantly share code, notes, and snippets.

@VRMink
Created March 14, 2014 13:11
Show Gist options
  • Save VRMink/9547403 to your computer and use it in GitHub Desktop.
Save VRMink/9547403 to your computer and use it in GitHub Desktop.
A simple reverse proxy for developing
var http = require('http'),
httpProxy = require('http-proxy');
//
// A simple round-robin load balancing strategy.
//
// First, list the servers you want to use in your rotation.
//
var forwarding = {
"s.paddle.to" : {
target: "http://localhost:8001"
},
"p.paddle.to" : {
target: "http://localhost:8002"
},
"q.paddle.to" : {
target: "http://localhost:8002"
}
};
var proxy = httpProxy.createServer();
http.createServer(function (req, res) {
var match = req.headers['host'].match(/.*([spq]\.paddle\.to)$/);
console.log(req.headers['host'], '->', match[1]);
proxy.web(req, res, forwarding[match[1]]);
}).listen(80);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment