Skip to content

Commit 46e0580

Browse files
committed
Fix bypass proxy middleware
The `bypass` feature was no longer working because the code added the bypass method as middleware AND `httpProxyMiddleware` as middleware. However, if a `bypass` method is given, it should only use that as middleware. This was caused in #359, and effects `1.15.0` and the 2.x branch.
1 parent f1ce64f commit 46e0580

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/Server.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,24 @@ function Server(compiler, options) {
169169
* ]
170170
*/
171171
options.proxy.forEach(function(proxyConfig) {
172+
var bypass = typeof proxyConfig.bypass === 'function';
172173
var context = proxyConfig.context || proxyConfig.path;
173174

174-
app.use(function(req, res, next) {
175-
if(typeof proxyConfig.bypass === 'function') {
176-
var bypassUrl = proxyConfig.bypass(req, res, proxyConfig) || false;
175+
function bypassMiddleware(req, res, next) {
176+
var bypassUrl = proxyConfig.bypass(req, res, proxyConfig) || false;
177177

178-
if(bypassUrl) {
179-
req.url = bypassUrl;
180-
}
178+
if(bypassUrl) {
179+
req.url = bypassUrl;
181180
}
182181

183182
next();
184-
}, httpProxyMiddleware(context, proxyConfig));
183+
}
184+
185+
if(bypass) {
186+
app.use(bypassMiddleware);
187+
} else {
188+
app.use(httpProxyMiddleware(context, proxyConfig));
189+
}
185190
});
186191
}
187192
},

0 commit comments

Comments
 (0)