Skip to content

Instantly share code, notes, and snippets.

@phlik
Created February 25, 2014 14:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phlik/9209972 to your computer and use it in GitHub Desktop.
Save phlik/9209972 to your computer and use it in GitHub Desktop.
Simple reverse proxy in node with url rewrite.
var http = require('http');
var httpProxy = require('http-proxy');
var proxy = httpProxy.createProxyServer();
http.createServer(function(req, res){
if(/^\/api/.test(req.url)){
req.url = req.url.replace(/^\/api/, "");
proxy.web(req, res, {target:'http://localhost:7889'});
} else {
proxy.web(req, res, {target:'http://localhost:6789'});
}
}).listen(2020);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment