From b993847874384b46543e24f22d522a91077f211a Mon Sep 17 00:00:00 2001 From: Steven Chim Date: Tue, 8 Sep 2015 21:54:21 +0200 Subject: [PATCH] fixed: path rewrite when agent is used. --- index.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index afaedf9d..ccfabe34 100644 --- a/index.js +++ b/index.js @@ -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); @@ -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));