Skip to content

Commit

Permalink
Merge pull request #23 from chimurai/proxy-agent-path-rewrite-fix
Browse files Browse the repository at this point in the history
fixed: path rewrite when agent is used.
  • Loading branch information
chimurai committed Sep 9, 2015
2 parents fe38d1a + b993847 commit 84e4211
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ var httpProxyMiddleware = function (context, opts) {

var pathRewriter = PathRewriter.create(proxyOptions.pathRewrite); // returns undefined when "pathRewrite" is not provided

// handle option.pathRewrite
if (pathRewriter) {
var proxyReqPathRewrite = function (proxyReq, req, res, options) {
proxyReq.path = pathRewriter(proxyReq.path);
};
proxy.on('proxyReq', proxyReqPathRewrite);
}

// Custom listener for the `proxyRes` event on `proxy`.
if (_.isFunction(proxyOptions.onProxyRes)) {
proxy.on('proxyRes', proxyOptions.onProxyRes);
Expand Down Expand Up @@ -58,6 +50,11 @@ var httpProxyMiddleware = function (context, opts) {
}

if (contextMatcher.match(config.context, req.url)) {
// handle option.pathRewrite
if (pathRewriter) {
req.url = pathRewriter(req.url);
}

if (proxyOptions.proxyTable) {
// change option.target when proxyTable present.
proxy.web(req, res, ProxyTable.createProxyOptions(req, proxyOptions));
Expand Down

0 comments on commit 84e4211

Please sign in to comment.