Skip to content

Instantly share code, notes, and snippets.

@tristola
Created August 30, 2014 10:15
Show Gist options
  • Save tristola/7e1e85087c0d4d15e708 to your computer and use it in GitHub Desktop.
Save tristola/7e1e85087c0d4d15e708 to your computer and use it in GitHub Desktop.
Node.js simple proxy
var http = require('http'),
httpProxy = require('http-proxy');
var proxy = httpProxy.createProxyServer({});
var server = require('http').createServer(function(req, res) {
if(req.url.indexOf('/rest')==0){
try{
proxy.web(req, res, { target: 'http://127.0.0.1:8888'+req.url });
}catch(err){
}
} else {
proxy.web(req, res, { target: 'http://127.0.0.1:3000'});
}
});
server.listen(5050);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment