Created
November 6, 2013 22:50
-
-
Save robert52/7345646 to your computer and use it in GitHub Desktop.
Proxy requests between two node.js applications using 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 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