Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created June 25, 2012 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raynos/2991163 to your computer and use it in GitHub Desktop.
Save Raynos/2991163 to your computer and use it in GitHub Desktop.
Proxying an entire HTTP request if we don't know how to handle it
var serverOne = http.createServer(function (req, res) {
var route = this.router.match(req.url)
if (!route) {
proxyTo(req, res, "http://localhost:8081")
}
route.fn(req, res, route.params, route.splats)
}).listen(8080)
var serverTwo = http.createServer(function (req, res) {
...
}).listen(8081)
function proxyTo(req, res, serverIdentifier) {
/* node 0.6 */
req.pipe(request(serverIdentifier + req.url)).pipe(res)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment