Skip to content

Commit

Permalink
fix: Remove fallback middleware also after Vite restart (#18455)
Browse files Browse the repository at this point in the history
The existing hacky way of removing the middleware has two issues:

1. It removes it AFTER the first request to a non-existing file so the first request for a non-existing resources index.html and subsequent requests return 404

2. It does not work with Vite 4.0.5+ after restart, see vitejs/vite#15589

Co-authored-by: Peter Czuczor <[email protected]>
  • Loading branch information
Artur- and czp13 authored Jan 22, 2024
1 parent b533f9e commit ae7e360
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions flow-server/src/main/resources/vite.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,6 @@ function runWatchDog(watchDogPort, watchDogHost) {
client.connect(watchDogPort, watchDogHost || 'localhost');
}

let spaMiddlewareForceRemoved = false;

const allowedFrontendFolders = [frontendFolder, nodeModulesFolder];

function showRecompileReason(): PluginOption {
Expand Down Expand Up @@ -773,18 +771,14 @@ export const vaadinConfig: UserConfigFn = (env) => {
}),
{
name: 'vaadin:force-remove-html-middleware',
transformIndexHtml: {
order: 'pre',
handler(_html, { server }) {
if (server && !spaMiddlewareForceRemoved) {
server.middlewares.stack = server.middlewares.stack.filter((mw) => {
const handleName = '' + mw.handle;
return !handleName.includes('viteHtmlFallbackMiddleware');
});
spaMiddlewareForceRemoved = true;
}
}
}
configureServer(server) {
return () => {
server.middlewares.stack = server.middlewares.stack.filter((mw) => {
const handleName = `${mw.handle}`;
return !handleName.includes('viteHtmlFallbackMiddleware');
});
};
},
},
hasExportedWebComponents && {
name: 'vaadin:inject-entrypoints-to-web-component-html',
Expand Down

0 comments on commit ae7e360

Please sign in to comment.