Skip to content

fix: use Vercel rewrites for content negotiation (Accept: text/markdown)#27

Merged
rachaelrenk merged 1 commit intomainfrom
rachael/fix-content-negotiation-v2
May 6, 2026
Merged

fix: use Vercel rewrites for content negotiation (Accept: text/markdown)#27
rachaelrenk merged 1 commit intomainfrom
rachael/fix-content-negotiation-v2

Conversation

@rachaelrenk
Copy link
Copy Markdown
Contributor

Summary

Fixes content negotiation for Accept: text/markdown requests by using Vercel's built-in rewrites instead of Astro edge middleware.

Why the previous approach failed

PR #25 added middlewareMode: 'edge' to deploy the Astro middleware as a Vercel Edge Function. This doesn't work for pre-rendered static pages because the edge function's next() callback forwards requests to /_render (the Astro server), which doesn't exist for static pages. The CDN just serves the cached HTML regardless.

What this PR does

  1. Reverts middlewareMode: 'edge' back to the default vercel()
  2. Adds Vercel rewrites in vercel.json with has header conditions:
{
  "source": "/:path+",
  "has": [{ "type": "header", "key": "accept", "value": ".*text/markdown.*" }],
  "destination": "/:path+.md"
}

This rewrites at the CDN level -- when an agent sends Accept: text/markdown, Vercel serves the .md file directly. No middleware, no serverless function, no edge function needed.

The Astro middleware in src/middleware.ts is kept for dev mode (where it works correctly since the Astro dev server handles all requests).

Expected impact

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

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

…leware

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 <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 11:56pm

Request Review

@rachaelrenk rachaelrenk merged commit ef1e600 into main May 6, 2026
8 of 9 checks passed
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.

2 participants