Skip to content
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

Refactor webpack-dev-server middleware application logic #5149

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions lib/Server.js
Expand Up @@ -552,6 +552,35 @@ class Server {
searchParams.set("password", webSocketURL.password);
}

// Initialize an array to keep track of applied middleware
const appliedMiddleware = [];

// Function to apply middleware only once
function applyMiddlewareOnce(middleware) {
// Check if the middleware has already been applied
if (!appliedMiddleware.includes(middleware)) {
// Apply the middleware
this.app.use(middleware);

// Add the middleware to the applied middleware array
appliedMiddleware.push(middleware);
}
}

// Apply middleware for each feature only once
if (this.options.proxy) {
applyMiddlewareOnce.call(this, proxyMiddleware);
}

if (this.options.contentBase !== false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have contentBase anymore

applyMiddlewareOnce.call(this, contentBaseMiddleware);
}

if (this.options.historyApiFallback) {
applyMiddlewareOnce.call(this, historyApiFallbackMiddleware);
}


/** @type {string} */
let hostname;

Expand Down