The new proxy library used in 1.15 uses a different glob syntax, so this configuration:
{
devServer: {
proxy: {
"*": {
target: proxyUrl,
secure: false,
},
},
},
};
works in 1.14, but not 1.15. In 1.15, it needs to be ** instead of *.
Should we add a warning or something to aid in upgrading?
I've just found this same issue, @mzgoddard helped me. This was apparently introduced migrating from http-proxy to http-proxy-middleware. (https://github.com/webpack/webpack-dev-server/commit/7b3f12e542562d0a50c1dcabb378798dd2beff05)
It looks like this '*' pattern is pretty common, so this might be an annoying breaking change in the semver releases.
In the meanwhile can we set a translation for this pattern to match ' **'? This would be easy to remove releasing the version 2 already in beta.
It looks like this is a duplicate of #561 and #560
at least '**' is a compatible glob in 1.14.1, so it won't break someone's instance by any missed version bump on the webpack-dev-server version.
Also in version 2.1.0-beta.0
:/
This is a fairly annoying breaking change to just automatically get - I would appreciate at _least_ a warning if using *. Preferably, automatically mapping * to ** would be a lot more helpful.
Changing * or /* to ** solved the HPM the error but bypass doesn't do anything anymore. Everything is sent to the proxy.
I've used the custom matching option of the proxy middleware instead of the bypass option.
...
proxy: [
{
context: function(pathname, req) {
// only proxy the api and the login post call to the node backend
return pathname.match("^/api") || (pathname.match("^/login") && req.method === "POST")
},
target: {
port: 3000
}
}
]
...
Hope this helps anyone.
Hm, sorry that this happened. In PR #359, which implemented the switch from http-proxy to http-proxy-middleware, there seemed to be only one breaking change. This was fixed for backwards compatibility with commit 33ebd1f9f702068ed850227ef7c74065dc3849e7.
As for the bypass option not working, let's continue that discussion in #560.
As of 314048e54baeb54ba6aa9e9d6081038f803c43fe, using * as a context should work again. Internally, it will be remapped to **. Can you guys check if that works for you?
The easiest way to test this, is to replace the contents of node_modules/webpack-dev-server/lib/Server.js with this file.
I was surprised by this too, only by stumbling across this issue did I understand what had happened. Also, I think the webpack-dev-server documentation is now inconsistent, since the proxy comment in the API section says the following, whereas it should be stipulating ** instead:
// Set this if you want webpack-dev-server to delegate a single path to an arbitrary server.
// Use "*" to proxy all paths to the specified server.
@aknuds1, see my comment above. It is getting fixed ;).
@SpaceK33z Yeah I saw that, but the webpack-dev-server documentation is still inconsistent, isn't it? It confused me quite a bit when I was re-reading it, to figure out what might be happening.
Ah yeah, true, that should be fixed now.
@SpaceK33z Thanks!
It works for me! Thanks, @SpaceK33z!
@mischi and me are also having issues when using a proxy and HTTPS with own certificates (key, crt and ca).
With 1.14.2 we could do a redirect from localhost/abc to localhost:
module.exports.devServer.proxy = {
'/abc/**': {
target: 'https://localhost:8080',
rewrite: function rewrite(req) {
req.url = req.url.replace(/^\/abc/, '');
},
},
now we are getting
[HPM] PROXY ERROR: UNABLE_TO_VERIFY_LEAF_SIGNATURE. localhost -> https://localhost:8080/abc/
on the console and
Error occured while trying to proxy to: localhost:8080/abc/
inside the browser.
@davidreher, this could be related to #566. As a workaround, you can use pathRewrite from http-proxy-middleware. If that still doesn't work, try adding secure: false.
@SpaceK33z pathRewrite was part of the problem. Finally adding secure: false did the trick. Thx for the quick support :+1:
This problem has been fixed with [email protected]. * is now rewritten to ** internally.
Most helpful comment
@davidreher, this could be related to #566. As a workaround, you can use
pathRewritefrom http-proxy-middleware. If that still doesn't work, try addingsecure: false.