From a3cc17406fc31cb157ac5ff8a04c8a05d1d38927 Mon Sep 17 00:00:00 2001 From: Rachael Rose Renk <91027132+rachaelrenk@users.noreply.github.com> Date: Tue, 5 May 2026 13:54:51 -1000 Subject: [PATCH] fix: use Vercel rewrites for content negotiation instead of edge middleware MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The middlewareMode: 'edge' approach doesn't work with pre-rendered static pages — the edge function's next() forwards to /_render (the Astro server), which doesn't exist for static pages. Instead, use Vercel's built-in rewrites with header conditions in vercel.json. When an agent sends Accept: text/markdown, Vercel rewrites the request to the .md variant at the CDN level — no middleware needed. The Astro middleware in src/middleware.ts is kept for dev mode. Co-Authored-By: Oz --- astro.config.mjs | 6 +----- vercel.json | 12 ++++++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/astro.config.mjs b/astro.config.mjs index a50ea08..f330868 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -166,9 +166,5 @@ export default defineConfig({ }), docsMarkdownIntegration(), ], - // Deploy Astro middleware as a Vercel Edge Function so it runs at - // request time for ALL pages, including pre-rendered static pages. - // Without this, middleware only runs at build time for static pages - // and content negotiation (Accept: text/markdown) doesn't work. - adapter: vercel({ middlewareMode: 'edge' }), + adapter: vercel(), }); diff --git a/vercel.json b/vercel.json index 6d747ef..1d5ad06 100644 --- a/vercel.json +++ b/vercel.json @@ -70,6 +70,18 @@ ] } ], + "rewrites": [ + { + "source": "/", + "has": [{ "type": "header", "key": "accept", "value": ".*text/markdown.*" }], + "destination": "/index.md" + }, + { + "source": "/:path+", + "has": [{ "type": "header", "key": "accept", "value": ".*text/markdown.*" }], + "destination": "/:path+.md" + } + ], "redirects": [ { "source": "/advanced/command-line-flags",