Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(kb) - add in content negotiation support (#51801)

Kody Jacksonebfe057c9aaf
diff --git a/apps/kb/AGENTS.md b/apps/kb/AGENTS.md
index e333f62d860..8f2ab71c5f4 100644
--- a/apps/kb/AGENTS.md
+++ b/apps/kb/AGENTS.md
@@ -57,12 +57,16 @@ content files, and read from every collection.
Separately, `scripts/generate-markdown.mjs` runs as a `prebuild` step and exports every content file — plus
one page per topic, listing its guides — as a plain `.md` file under the gitignored `public/markdown/`,
mirroring the page's URL with a `.md` extension. `vercel.json` permanently redirects `<page>.md` requests to
-these generated files, one redirect entry per route section (`guides`, `topics`, `troubleshooting`).
-
-If you add a new content collection or top-level route, add a matching redirect in `vercel.json`
-(`/kb/<section>/:path+.md` → `/kb/markdown/<section>/:path+.md`), and check whether `generate-markdown.mjs`
-needs updating too — the content export falls out of its generic `src/content/**` walk automatically, but
-per-topic-style listing pages don't.
+these generated files, one redirect entry per route section (`guides`, `topics`, `troubleshooting`). It also
+rewrites guide, topic, and troubleshooting page requests that send `Accept: text/markdown` to the same files
+(content negotiation), and sets `Vary: Accept` on those pages. The negotiated rewrites must stay above the generic
+`/kb/:path*` rewrite, since Vercel uses the first match.
+
+If you add a new content collection or top-level route, add a matching redirect, negotiated rewrite, and
+`Vary: Accept` header in `vercel.json` (`/kb/<section>/:path+.md` → `/kb/markdown/<section>/:path+.md`, the
+`Accept` rewrite to `/markdown/<section>/:path+.md`, and a `headers` entry for `/kb/<section>/:path+`), and
+check whether `generate-markdown.mjs` needs updating too — the content export falls out of its generic
+`src/content/**` walk automatically, but per-topic-style listing pages don't.
## Topic-specific guidance
diff --git a/apps/kb/vercel.json b/apps/kb/vercel.json
index 1b5f675311a..e0c25d8f82a 100644
--- a/apps/kb/vercel.json
+++ b/apps/kb/vercel.json
@@ -19,7 +19,36 @@
}
],
"rewrites": [
+ {
+ "source": "/kb/guides/:path+",
+ "has": [{ "type": "header", "key": "accept", "value": "(?i).*text/markdown.*" }],
+ "destination": "/markdown/guides/:path+.md"
+ },
+ {
+ "source": "/kb/topics/:path+",
+ "has": [{ "type": "header", "key": "accept", "value": "(?i).*text/markdown.*" }],
+ "destination": "/markdown/topics/:path+.md"
+ },
+ {
+ "source": "/kb/troubleshooting/:path+",
+ "has": [{ "type": "header", "key": "accept", "value": "(?i).*text/markdown.*" }],
+ "destination": "/markdown/troubleshooting/:path+.md"
+ },
{ "source": "/kb", "destination": "/index.html" },
{ "source": "/kb/:path*", "destination": "/:path*" }
+ ],
+ "headers": [
+ {
+ "source": "/kb/guides/:path+",
+ "headers": [{ "key": "Vary", "value": "Accept" }]
+ },
+ {
+ "source": "/kb/topics/:path+",
+ "headers": [{ "key": "Vary", "value": "Accept" }]
+ },
+ {
+ "source": "/kb/troubleshooting/:path+",
+ "headers": [{ "key": "Vary", "value": "Accept" }]
+ }
]
}