Skip to content

Instantly share code, notes, and snippets.

@robert52
Created November 6, 2013 22:50
Show Gist options
  • Save robert52/7345646 to your computer and use it in GitHub Desktop.
Save robert52/7345646 to your computer and use it in GitHub Desktop.
Proxy requests between two node.js applications using node-http-proxy
var httpProxy = require('http-proxy');
var fs = require('fs');
var options = {
router : {
'localhost/api': '127.0.0.1:3030/api',
//default route
'localhost/.*': '127.0.0.1:3031'
}
};
var router = new httpProxy.RoutingProxy(options);
var proxy = httpProxy.createServer(function(req,res) {
console.log("request: " + req.url + "; method: " + req.method);
//fs.appendFile('./logs/access_log.txt', "request: " + req.url + "; method: " + req.method); //storing to file
router.proxyRequest(req,res);
});
proxy.listen(3001, function() { console.log("Routing proxy listening on " + proxy.address().port); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment