Skip to content

Commit 97ef7b5

Browse files
authored
Fix bypass proxy middleware (#563)
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 314048e commit 97ef7b5

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lib/Server.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,25 @@ function Server(compiler, options) {
170170
* ]
171171
*/
172172
options.proxy.forEach(function(proxyConfig) {
173+
var bypass = typeof proxyConfig.bypass === 'function';
173174
var context = proxyConfig.context || proxyConfig.path;
175+
var proxyMiddleware;
176+
// It is possible to use the `bypass` method without a `target`.
177+
// However, the proxy middleware has no use in this case, and will fail to instantiate.
178+
if(proxyConfig.target) {
179+
proxyMiddleware = httpProxyMiddleware(context, proxyConfig);
180+
}
174181

175182
app.use(function(req, res, next) {
176-
if(typeof proxyConfig.bypass === 'function') {
177-
var bypassUrl = proxyConfig.bypass(req, res, proxyConfig) || false;
183+
var bypassUrl = bypass && proxyConfig.bypass(req, res, proxyConfig) || false;
178184

179-
if(bypassUrl) {
180-
req.url = bypassUrl;
181-
}
185+
if(bypassUrl) {
186+
req.url = bypassUrl;
187+
next();
188+
} else if(proxyMiddleware) {
189+
return proxyMiddleware(req, res, next);
182190
}
183-
184-
next();
185-
}, httpProxyMiddleware(context, proxyConfig));
191+
});
186192
});
187193
}
188194
},

0 commit comments

Comments
 (0)