Merge pull request #21003 from gustavotrott/webpack-fix

fix (html5-dev-server): Prevent HEAD requests from crashing webpack-dev-server
This commit is contained in:
Gustavo Trott 2024-08-22 18:17:18 -03:00 committed by GitHub
commit f4749b0e96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -110,6 +110,25 @@ if (env === prodEnv) {
overlay: false,
webSocketURL: 'auto://0.0.0.0:0/html5client/ws',
},
setupMiddlewares: (middlewares, devServer) => {
if (!devServer) {
throw new Error('webpack-dev-server is not defined');
}
devServer.app.use((req, res, next) => {
// the server crashes when it receives HEAD requests, so we need to prevent it
if (req.method === 'HEAD') {
// console.log(`Request received: ${req.method} ${req.url}`);
res.setHeader('Content-Type', 'text/html');
res.setHeader('Content-Length', '0');
res.end();
} else {
next();
}
});
return middlewares;
},
};
}