Skip to content

Commit e58637a

Browse files
committed
Proxy target was ignored when using bypass method.
1 parent 46e0580 commit e58637a

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

lib/Server.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -171,22 +171,23 @@ function Server(compiler, options) {
171171
options.proxy.forEach(function(proxyConfig) {
172172
var bypass = typeof proxyConfig.bypass === 'function';
173173
var context = proxyConfig.context || proxyConfig.path;
174+
var proxyMiddleware;
175+
// It is possible to use the `bypass` method without a `target`.
176+
// However, the proxy middleware has no use in this case, and will fail to instantiate.
177+
if (proxyConfig.target) {
178+
proxyMiddleware = httpProxyMiddleware(context, proxyConfig);
179+
}
174180

175-
function bypassMiddleware(req, res, next) {
176-
var bypassUrl = proxyConfig.bypass(req, res, proxyConfig) || false;
181+
app.use(function(req, res, next) {
182+
var bypassUrl = bypass && proxyConfig.bypass(req, res, proxyConfig) || false;
177183

178184
if(bypassUrl) {
179185
req.url = bypassUrl;
186+
next();
187+
} else if (proxyMiddleware) {
188+
return proxyMiddleware(req, res, next);
180189
}
181-
182-
next();
183-
}
184-
185-
if(bypass) {
186-
app.use(bypassMiddleware);
187-
} else {
188-
app.use(httpProxyMiddleware(context, proxyConfig));
189-
}
190+
});
190191
});
191192
}
192193
},

0 commit comments

Comments
 (0)