Skip to content

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

fix(www): changelog md negotiation slug-set gate (#49357)

Pamela Chiaf20874343288
diff --git a/apps/www/middleware.test.ts b/apps/www/middleware.test.ts
index 6950e7c6c7c..9e486bef4f8 100644
--- a/apps/www/middleware.test.ts
+++ b/apps/www/middleware.test.ts
@@ -11,6 +11,7 @@ import { middleware } from './middleware'
vi.mock('./app/api-v2/md/content.generated', () => ({
MD_CONTENT: new Map<string, string>(),
MD_PAGES: new Set<string>(['homepage', 'auth', 'pricing']),
+ CHANGELOG_PAGES: new Set<string>(['changelog', 'changelog/100', 'changelog/pipelines']),
}))
function makeRequest(
@@ -132,6 +133,18 @@ describe('www middleware', () => {
expect(res.headers.get('x-middleware-rewrite')).toBe('https://supabase.com/changelog/100.md')
})
+ it('serves markdown for explicit non-legacy changelog .md requests even when Accept excludes it', () => {
+ const req = makeRequest('/changelog/pipelines.md', {
+ accept: 'application/x-content-negotiation-probe',
+ })
+ const res = middleware(req)
+
+ expect(res.status).not.toBe(406)
+ expect(res.headers.get('x-middleware-rewrite')).toBe(
+ 'https://supabase.com/changelog/pipelines.md'
+ )
+ })
+
it('rewrites the changelog index .md request without doubling the suffix', () => {
const req = makeRequest('/changelog.md', { accept: 'text/markdown' })
const res = middleware(req)
@@ -185,6 +198,31 @@ describe('www middleware', () => {
expect(res.headers.get('x-middleware-rewrite')).toBe('https://supabase.com/changelog/100.md')
})
+ it('negotiates markdown for non-legacy changelog slugs', () => {
+ const req = makeRequest('/changelog/pipelines', { accept: 'text/markdown' })
+ const res = middleware(req)
+
+ expect(res.headers.get('x-middleware-rewrite')).toBe(
+ 'https://supabase.com/changelog/pipelines.md'
+ )
+ })
+
+ it('passes through unpublished numeric-prefix changelog slugs', () => {
+ const req = makeRequest('/changelog/999-not-published', { accept: 'text/markdown' })
+ const res = middleware(req)
+
+ expect(res.headers.get('x-middleware-rewrite')).toBeNull()
+ expect(res.status).not.toBe(406)
+ })
+
+ it('passes through deep paths under a published changelog slug', () => {
+ const req = makeRequest('/changelog/100/bar', { accept: 'text/markdown' })
+ const res = middleware(req)
+
+ expect(res.headers.get('x-middleware-rewrite')).toBeNull()
+ expect(res.status).not.toBe(406)
+ })
+
it('rewrites the bare changelog index to its static .md file', () => {
const req = makeRequest('/changelog', { accept: 'text/markdown' })
const res = middleware(req)
@@ -291,6 +329,15 @@ describe('www middleware', () => {
expect(res.status).toBe(406)
})
+ it('returns 406 for non-legacy changelog entries when Accept matches nothing', () => {
+ const req = makeRequest('/changelog/pipelines', {
+ accept: 'application/x-content-negotiation-probe',
+ })
+ const res = middleware(req)
+
+ expect(res.status).toBe(406)
+ })
+
it('sets Cache-Control: no-store and Vary: Accept on 406 responses', () => {
const req = makeRequest('/pricing', { accept: 'application/x-content-negotiation-probe' })
const res = middleware(req)
diff --git a/apps/www/middleware.ts b/apps/www/middleware.ts
index ab96127d5ee..75aa9a99537 100644
--- a/apps/www/middleware.ts
+++ b/apps/www/middleware.ts
@@ -2,7 +2,7 @@ import { stampFirstReferrerCookie } from 'common/first-referrer-cookie'
import { negotiateMarkdown } from 'common/markdown-negotiation'
import { NextResponse, type NextRequest } from 'next/server'
-import { MD_PAGES } from './app/api-v2/md/content.generated'
+import { CHANGELOG_PAGES, MD_PAGES } from './app/api-v2/md/content.generated'
export function middleware(request: NextRequest) {
const { pathname } = request.nextUrl
@@ -14,7 +14,7 @@ export function middleware(request: NextRequest) {
// entry — NextURL preserves trailing-slash style on rewrite targets.
const slug = (basePathname === '/' ? 'homepage' : basePathname.slice(1)).replace(/\/$/, '')
const isMdEligible = MD_PAGES.has(slug)
- const isChangelogEntry = slug === 'changelog' || /^changelog\/\d+/.test(slug)
+ const isChangelogEntry = CHANGELOG_PAGES.has(slug)
const decision = negotiateMarkdown(
{ acceptHeader: request.headers.get('accept') ?? '' },
diff --git a/apps/www/scripts/generateMdContent.mjs b/apps/www/scripts/generateMdContent.mjs
index 2dddb0351e3..842a9c10811 100644
--- a/apps/www/scripts/generateMdContent.mjs
+++ b/apps/www/scripts/generateMdContent.mjs
@@ -17,6 +17,7 @@ import { mdxBodyToMarkdown } from './lib/mdxToMarkdown.mjs'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const wwwDir = path.join(__dirname, '..')
const contentDir = path.join(wwwDir, 'content/md')
+const changelogMdDir = path.join(wwwDir, 'public/changelog')
const outputPath = path.join(wwwDir, 'app/api-v2/md/content.generated.ts')
// Matches lib/posts.tsx FILENAME_SUBSTRING — strips YYYY-MM-DD- (11 chars).
@@ -213,6 +214,40 @@ for (const entry of allEntries) {
seen.add(entry.slug)
}
+// public/changelog/*.md is written by generateStaticContent.mjs earlier in
+// content:build:core; absent locally e.g. when CHANGELOG_SYNC_APP_* secrets are unset.
+const changelogSlugs = (await collectMdFiles(changelogMdDir, 'changelog')).sort()
+
+// The middleware matches request slugs against these keys verbatim, and its
+// tests mock this set — a dropped prefix would ship silently with green tests.
+if (changelogSlugs.some((s) => !s.startsWith('changelog/'))) {
+ console.error('❌ Changelog slugs must carry the changelog/ prefix the middleware matches on.')
+ process.exit(1)
+}
+
+if (changelogSlugs.length === 0) {
+ if (process.env.VERCEL) {
+ console.error(
+ '❌ No changelog slugs found in public/changelog — changelog generation produced nothing.'
+ )
+ process.exit(1)
+ }
+ console.warn(
+ '⚠️ No changelog slugs found in public/changelog — changelog md negotiation off in this build'
+ )
+}
+
+let changelogIndexExists = false
+try {
+ await fs.access(path.join(wwwDir, 'public/changelog.md'))
+ changelogIndexExists = true
+} catch (err) {
+ if (err.code !== 'ENOENT') throw err
+}
+if (changelogIndexExists) {
+ changelogSlugs.unshift('changelog')
+}
+
const contentEntries = liveEntries
.map((e) => ` [${JSON.stringify(e.slug)}, ${JSON.stringify(e.content)}]`)
.join(',\n')
@@ -228,9 +263,11 @@ ${contentEntries},
export const MD_PAGES = new Set<string>([
${pageEntries},
])
+
+export const CHANGELOG_PAGES = new Set<string>(${JSON.stringify(changelogSlugs, null, 2)})
`
await fs.writeFile(outputPath, output, 'utf-8')
console.log(
- `✅ Generated ${outputPath} (${liveEntries.length} files, ${allPageSlugs.length} pages)`
+ `✅ Generated ${outputPath} (${liveEntries.length} files, ${allPageSlugs.length} pages, ${changelogSlugs.length} changelog)`
)