Skip to content

Instantly share code, notes, and snippets.

@nnnnathann
Created February 3, 2014 14:05
Show Gist options
  • Save nnnnathann/8784394 to your computer and use it in GitHub Desktop.
Save nnnnathann/8784394 to your computer and use it in GitHub Desktop.
Connect Proxy
var url = require('url');
var httpProxy = require('http-proxy');
var proxy = new httpProxy.RoutingProxy();
module.exports = function(apiUrl, stripRoute){
return function(req,res,next){
var pathInfo = url.parse(apiUrl);
if(/^\/api/.exec(req.url)){
if(stripRoute){
req.url = req.url.replace(/^\/api/,'');
}
req.headers.host = pathInfo.host;
proxy.proxyRequest(req, res, pathInfo);
}else{
next();
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment