Skip to content

fix: deploy middleware as Vercel Edge Function for content negotiation#26

Closed
rachaelrenk wants to merge 1 commit intomainfrom
rachael/fix-content-negotiation
Closed

fix: deploy middleware as Vercel Edge Function for content negotiation#26
rachaelrenk wants to merge 1 commit intomainfrom
rachael/fix-content-negotiation

Conversation

@rachaelrenk
Copy link
Copy Markdown
Contributor

Summary

One-line fix: vercel() to vercel({ middlewareMode: 'edge' }).

The content negotiation middleware from PR #23 wasn't working in production because pre-rendered pages are served as static files by Vercel's CDN -- the Astro middleware never runs at request time for them.

Root cause

The default middlewareMode: 'classic' only runs middleware:

  • At build time for pre-rendered (static) pages
  • At request time for SSR pages

Since all doc pages are pre-rendered, the Accept: text/markdown check in src/middleware.ts was only evaluated during the build, not when agents actually request pages.

Fix

middlewareMode: 'edge' deploys the Astro middleware as a separate Vercel Edge Function that runs at request time for ALL requests, including static pages.

Expected impact

The content-negotiation AFDocs check should flip from FAIL to PASS, bringing the score from 88 (B+) toward 93+ (A).

Co-Authored-By: Oz oz-agent@warp.dev

The Astro middleware in src/middleware.ts was not running at request time
for pre-rendered (static) pages. The default middlewareMode ('classic')
only executes middleware at build time for static pages, so Accept:
text/markdown requests were served HTML from Vercel's CDN cache.

Setting middlewareMode: 'edge' deploys the middleware as a separate
Vercel Edge Function that runs at request time for ALL requests,
including static pages. This enables content negotiation so agents
sending Accept: text/markdown get clean markdown automatically.

Co-Authored-By: Oz <oz-agent@warp.dev>
@cla-bot cla-bot Bot added the cla-signed label May 5, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented May 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment May 5, 2026 10:59pm

Request Review

@rachaelrenk
Copy link
Copy Markdown
Contributor Author

Moved to PR #25 instead.

@rachaelrenk rachaelrenk closed this May 5, 2026
@rachaelrenk rachaelrenk deleted the rachael/fix-content-negotiation branch May 5, 2026 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant