-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
behavior of static and historyApiFallback #2716
Comments
Yes, if the |
|
Partially fixed #4501 |
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 webpack-dev-server/lib/Server.js Lines 2174 to 2189 in 49efdf8
My understanding is that if you're using In my case I'm only proxying a single endpoint, so I've configured |
I think we can improve/fix:
So we will always pass options even you don't have router, what do you think? |
This commit refactors the middleware application logic in the webpack-dev-server codebase to ensure that middleware is applied only once, regardless of how many times it's called. Previously, certain middleware, such as static serving middleware, was being applied multiple times to support features like `historyApiFallback`. This refactor eliminates duplicate middleware application by introducing a mechanism to track applied middleware and applying each middleware only once. Changes: - Introduced `appliedMiddleware` array to track applied middleware. - Created `applyMiddlewareOnce` function to apply middleware only if it hasn't been applied before. - Updated webpack-dev-server codebase to utilize `applyMiddlewareOnce` for applying middleware associated with various features. This update aims to improve code efficiency and prevent unintended behavior or performance issues caused by duplicate middleware application. Fixes: webpack#2716
Expected Behavior
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:webpack-dev-server/lib/Server.js
Lines 548 to 559 in 4ab1f21
Solution
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.
The text was updated successfully, but these errors were encountered: