Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Proxy target was ignored when using bypass method.
  • Loading branch information
SpaceK33z committed Aug 23, 2016
commit 87ac5ae4c5058ade1084ca139eb1a8e0efcfb7ba
23 changes: 12 additions & 11 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,23 @@ 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);
}

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

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

next();
}

if(bypass) {
app.use(bypassMiddleware);
} else {
app.use(httpProxyMiddleware(context, proxyConfig));
}
});
});
}
},
Expand Down