Created
February 19, 2014 06:44
-
-
Save indexzero/9087173 to your computer and use it in GitHub Desktop.
URL to host rewrite proxying with node-http-proxy
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 httpProxy = require('http-proxy') | |
var proxy = httpProxy.createProxy(); | |
var fulltld = 'my-own-domain.com'; | |
var options = { | |
'/first-target': 'first-target', | |
'/second-target': 'second-target' | |
} | |
require('http').createServer(function(req, res) { | |
if (!options[req.url]) { | |
return res.end(400); | |
} | |
// | |
// Need to change the URL here. | |
// | |
var dest = req.url; | |
req.url = '/'; | |
proxy.web(req, res, { | |
target: options[req.url] + '.' + fulltld; | |
}); | |
}).listen(8000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And how can I rewrite the host but PREVIOUSLY get the data from the req.on('data') event?