webpack-dev-server
webpack-dev-server copied to clipboard
Refactor webpack-dev-server middleware application logic
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
appliedMiddlewarearray to track applied middleware. - Created
applyMiddlewareOncefunction to apply middleware only if it hasn't been applied before. - Updated webpack-dev-server codebase to utilize
applyMiddlewareOncefor 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: #2716
- [ ] This is a bugfix
- [ ] This is a feature
- [x] This is a code refactor
- [ ] This is a test update
- [ ] This is a docs update
- [ ] This is a metadata update