Created
February 3, 2014 14:05
-
-
Save nnnnathann/8784394 to your computer and use it in GitHub Desktop.
Connect 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 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