Skip to content

Commit

Permalink
fixed: path rewrite when agent is used.
Browse files Browse the repository at this point in the history
  • Loading branch information
chimurai committed Sep 8, 2015
1 parent fe38d1a commit b993847
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 b993847

Please sign in to comment.