Skip to content

Commit

Permalink
Remove hardcoded Vite middleware handling (#4531)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Aug 29, 2022
1 parent ca28d75 commit 2d2e38e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-frogs-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Remove hardcoded Vite middleware handling
1 change: 0 additions & 1 deletion packages/astro/src/core/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class AstroBuilder {
hmr: false,
middlewareMode: true,
},
appType: 'custom',
},
{ astroConfig: this.config, logging, mode: 'build' }
);
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export async function createVite(
cacheDir: fileURLToPath(new URL('./node_modules/.vite/', astroConfig.root)), // using local caches allows Astro to be used in monorepos, etc.
clearScreen: false, // we want to control the output, not Vite
logLevel: 'warn', // log warnings and errors only
appType: 'custom',
optimizeDeps: {
entries: ['src/**/*'],
exclude: ['node-fetch'],
Expand Down
16 changes: 0 additions & 16 deletions packages/astro/src/vite-plugin-astro-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@ interface AstroPluginOptions {
logging: LogOptions;
}

const BAD_VITE_MIDDLEWARE = [
'viteIndexHtmlMiddleware',
'vite404Middleware',
'viteSpaFallbackMiddleware',
];
function removeViteHttpMiddleware(server: vite.Connect.Server) {
for (let i = server.stack.length - 1; i > 0; i--) {
// @ts-expect-error using internals until https://github.com/vitejs/vite/pull/4640 is merged
if (BAD_VITE_MIDDLEWARE.includes(server.stack[i].handle.name)) {
server.stack.splice(i, 1);
}
}
}

function truncateString(str: string, n: number) {
if (str.length > n) {
return str.substring(0, n) + '…';
Expand Down Expand Up @@ -386,8 +372,6 @@ export default function createPlugin({ config, logging }: AstroPluginOptions): v
viteServer.watcher.on('unlink', rebuildManifest.bind(null, true));
viteServer.watcher.on('change', rebuildManifest.bind(null, false));
return () => {
removeViteHttpMiddleware(viteServer.middlewares);

// Push this middleware to the front of the stack so that it can intercept responses.
if (config.base !== '/') {
viteServer.middlewares.stack.unshift({
Expand Down

0 comments on commit 2d2e38e

Please sign in to comment.