Created
March 14, 2014 13:11
-
-
Save VRMink/9547403 to your computer and use it in GitHub Desktop.
A simple reverse proxy for developing
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 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