Created
June 25, 2012 20:53
-
-
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
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 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