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

Remove hardcoded Vite middleware handling #4531

Merged
merged 2 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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