You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Static serving middleware for the dev server should only need to be applied to the express server once via this.app.use(...)
Actual Behavior
static middleware is applied to the express server multiple times in order to make historyApiFallback work as expected. This is explained here: #2670 (comment)
A similar thing seems to have been added for the middleware feature as seen here, as it is added multiple times:
We need to find a way to either apply all of this middleware once without having any breaking changes, or have intentional slight breaking changes while only applying the middleware once. We should also look into if applying the same middleware many times causes performance losses, or if it is an acceptable thing to do.
I ran into this issue earlier and spent a few hours trying to debug it. In my case it turned out that configuring the webpack-dev-server proxy option with context and router options, but not target causes webpack-dev-server to ignore the context option when configuring the proxy:
My understanding is that if you're using router you don't need to specify target, but if I don't then webpack-dev-server configures the proxy to intercept every request, rather than just the requests that match the context.
In my case I'm only proxying a single endpoint, so I've configured context and target to the same value, and let the router reconfigure the target on each request. This appears to fix the conflict with historyApiFallback.
Activity
csr632 commentedon Feb 1, 2021
Yes, if the
proxyfeature or thehistoryApiFallbackfeature is enabled,http-proxy-middlewarewill be applied to the express server multiple times.alexander-akait commentedon Sep 13, 2021
historyApiFallbackalso break HEAD request in some cases, we need fix it, more information here webpack/webpack-dev-middleware#749chore: bump connect-history-api-fallback from 1.6.0 to 2.0.0 (webpack…
alexander-akait commentedon Jun 28, 2022
Partially fixed #4501
BRMatt commentedon Sep 28, 2022
I ran into this issue earlier and spent a few hours trying to debug it. In my case it turned out that configuring the webpack-dev-server
proxyoption withcontextandrouteroptions, but nottargetcauses webpack-dev-server to ignore thecontextoption when configuring the proxy:webpack-dev-server/lib/Server.js
Lines 2174 to 2189 in 49efdf8
My understanding is that if you're using
routeryou don't need to specifytarget, but if I don't then webpack-dev-server configures the proxy to intercept every request, rather than just the requests that match the context.In my case I'm only proxying a single endpoint, so I've configured
contextandtargetto the same value, and let the router reconfigure the target on each request. This appears to fix the conflict withhistoryApiFallback.alexander-akait commentedon Sep 28, 2022
I think we can improve/fix:
So we will always pass options even you don't have router, what do you think?
Refactor webpack-dev-server middleware application logic