Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,25 @@ function Server(compiler, options) {
* ]
*/
options.proxy.forEach(function(proxyConfig) {
var bypass = typeof proxyConfig.bypass === 'function';
var context = proxyConfig.context || proxyConfig.path;
var proxyMiddleware;
// It is possible to use the `bypass` method without a `target`.
// However, the proxy middleware has no use in this case, and will fail to instantiate.
if(proxyConfig.target) {
proxyMiddleware = httpProxyMiddleware(context, proxyConfig);
}

app.use(function(req, res, next) {
if(typeof proxyConfig.bypass === 'function') {
var bypassUrl = proxyConfig.bypass(req, res, proxyConfig) || false;
var bypassUrl = bypass && proxyConfig.bypass(req, res, proxyConfig) || false;

if(bypassUrl) {
req.url = bypassUrl;
}
if(bypassUrl) {
req.url = bypassUrl;
next();
} else if(proxyMiddleware) {
return proxyMiddleware(req, res, next);
}

next();
}, httpProxyMiddleware(context, proxyConfig));
});
});
}
},
Expand Down