Skip to content

Commit 2d2e38e

Browse files
authored
Remove hardcoded Vite middleware handling (#4531)
1 parent ca28d75 commit 2d2e38e

File tree

4 files changed

+6
-17
lines changed

4 files changed

+6
-17
lines changed

.changeset/fuzzy-frogs-try.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Remove hardcoded Vite middleware handling

packages/astro/src/core/build/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ class AstroBuilder {
7272
hmr: false,
7373
middlewareMode: true,
7474
},
75-
appType: 'custom',
7675
},
7776
{ astroConfig: this.config, logging, mode: 'build' }
7877
);

packages/astro/src/core/create-vite.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export async function createVite(
6565
cacheDir: fileURLToPath(new URL('./node_modules/.vite/', astroConfig.root)), // using local caches allows Astro to be used in monorepos, etc.
6666
clearScreen: false, // we want to control the output, not Vite
6767
logLevel: 'warn', // log warnings and errors only
68+
appType: 'custom',
6869
optimizeDeps: {
6970
entries: ['src/**/*'],
7071
exclude: ['node-fetch'],

packages/astro/src/vite-plugin-astro-server/index.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,6 @@ interface AstroPluginOptions {
2828
logging: LogOptions;
2929
}
3030

31-
const BAD_VITE_MIDDLEWARE = [
32-
'viteIndexHtmlMiddleware',
33-
'vite404Middleware',
34-
'viteSpaFallbackMiddleware',
35-
];
36-
function removeViteHttpMiddleware(server: vite.Connect.Server) {
37-
for (let i = server.stack.length - 1; i > 0; i--) {
38-
// @ts-expect-error using internals until https://github.com/vitejs/vite/pull/4640 is merged
39-
if (BAD_VITE_MIDDLEWARE.includes(server.stack[i].handle.name)) {
40-
server.stack.splice(i, 1);
41-
}
42-
}
43-
}
44-
4531
function truncateString(str: string, n: number) {
4632
if (str.length > n) {
4733
return str.substring(0, n) + '…';
@@ -386,8 +372,6 @@ export default function createPlugin({ config, logging }: AstroPluginOptions): v
386372
viteServer.watcher.on('unlink', rebuildManifest.bind(null, true));
387373
viteServer.watcher.on('change', rebuildManifest.bind(null, false));
388374
return () => {
389-
removeViteHttpMiddleware(viteServer.middlewares);
390-
391375
// Push this middleware to the front of the stack so that it can intercept responses.
392376
if (config.base !== '/') {
393377
viteServer.middlewares.stack.unshift({

0 commit comments

Comments
 (0)