mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
Nonexistent paths return a real 404 everywhere, but always with an HTML body, even when the client asked for markdown via `Accept: text/markdown` or a `.md` suffix. Middleware can't fix this: it gates on a static slug allowlist and can't know a path will 404. I added two `fallback` rewrites (`.md` suffix; Accept header containing `text/markdown` or `text/*`) that run only after every route has failed to match and route the request to a small `md-404` handler returning a short markdown 404 pointing at /docs, /sitemap.xml, and /llms.txt. Real pages are structurally unaffected. **Note:** `lib/rewrites.js` is untouched (the plain rewrites array became the `afterFiles` phase), so #49587 merges independently. I updated next.config.test.ts's rewrites assertion for the phased shape; it now also pins the two fallback rules. ## To test I verified on the Vercel preview: - [x] `curl -s -D - -H "Accept: text/markdown" <preview>/definitely-not-a-page` (404, `Content-Type: text/markdown`, body with the three pointers) - [x] Same URL with a browser Accept header (existing HTML 404, unchanged) - [x] `curl -s -D - <preview>/definitely-not-a-page.md` (markdown 404) - [x] `curl -s -D - -H "Accept: text/markdown" <preview>/auth` (200 markdown, unchanged) and `<preview>/support` (200 HTML, unchanged) - [x] `/homepage.md` still 308s to `/index.md` (redirects phase wins); `Accept: text/*` gets the markdown 404, matching real-page negotiation Known boundary: `/changelog/<unknown>` keeps the HTML 404 body (pages-router `fallback: 'blocking'` routes take priority over fallback rewrites per Next docs); the status is still 404, verified on the preview. ## Linear - fixes GROWTH-1142 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added Markdown-formatted 404 responses for unmatched documentation and `.md` page requests. - Included helpful documentation links in not-found responses. - Requests that explicitly accept Markdown now receive a consistent Markdown response. - Added appropriate response headers for security, caching, and content variation. - **Bug Fixes** - Improved routing for unmatched Markdown paths, ensuring they are handled by the appropriate not-found response instead of returning an unexpected format. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
31 lines
863 B
TypeScript
31 lines
863 B
TypeScript
import { NextResponse } from 'next/server'
|
|
|
|
const MARKDOWN_404_HEADERS = {
|
|
'Content-Type': 'text/markdown; charset=utf-8',
|
|
'X-Content-Type-Options': 'nosniff',
|
|
'Cache-Control': 'no-store',
|
|
Vary: 'Accept',
|
|
}
|
|
|
|
function buildMarkdown404Body(requestPath: string): string {
|
|
const safePath = requestPath.replace(/[^\x20-\x7E]/g, '').replaceAll('`', '')
|
|
return `# 404 Not Found
|
|
|
|
\`${safePath}\` does not exist on supabase.com.
|
|
|
|
Explore instead:
|
|
|
|
- [Documentation](https://supabase.com/docs)
|
|
- [Sitemap](https://supabase.com/sitemap.xml)
|
|
- [llms.txt](https://supabase.com/llms.txt)
|
|
`
|
|
}
|
|
|
|
export async function GET(_request: Request, { params }: { params: Promise<{ path?: string[] }> }) {
|
|
const { path } = await params
|
|
return new NextResponse(buildMarkdown404Body('/' + (path ?? []).join('/')), {
|
|
status: 404,
|
|
headers: MARKDOWN_404_HEADERS,
|
|
})
|
|
}
|