From 6f5626bcc3157d56f8538c60b328470db5386375 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Thu, 10 Sep 2026 23:55:48 -0600 Subject: [PATCH] site/api-md: Prerender /api/md/* at build time; enable Fluid compute Every doc page's markdown is now written as a static file during the build, so .md requests are served from the CDN instead of invoking a serverless function per request. Unknown slugs 404 without a function call (dynamicParams = false). vercel.json gains "fluid": true so the remaining functions (/api/og, the catch-all page renderer) share instances instead of cold-starting one per concurrent request. Amp-Thread-ID: https://ampcode.com/threads/T-01a08e2d-682f-75dd-a050-cb9bf8888dac Co-authored-by: Amp --- src/app/api/md/[...slug]/route.ts | 15 +++++++++++++-- vercel.json | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/app/api/md/[...slug]/route.ts b/src/app/api/md/[...slug]/route.ts index 5c8866022..51a3d8de6 100644 --- a/src/app/api/md/[...slug]/route.ts +++ b/src/app/api/md/[...slug]/route.ts @@ -1,8 +1,19 @@ import {allPosts} from 'contentlayer/generated'; -import {NextRequest, NextResponse} from 'next/server'; +import {NextResponse} from 'next/server'; + +// Prerender every post's markdown at build time; unknown slugs 404 without +// invoking a function. +export const dynamicParams = false; + +export function generateStaticParams() { + // The root index.mdx has an empty path; a catch-all needs at least one segment. + return allPosts + .filter(post => post._raw.flattenedPath !== '') + .map(post => ({slug: post._raw.flattenedPath.split('/')})); +} export async function GET( - _: NextRequest, + _: Request, {params}: {params: {slug: string[]}} ) { const docPath = params.slug.join('/'); diff --git a/vercel.json b/vercel.json index 1625d94ae..7e1c6b897 100644 --- a/vercel.json +++ b/vercel.json @@ -1,4 +1,5 @@ { "$schema": "https://openapi.vercel.sh/vercel.json", + "fluid": true, "ignoreCommand": "git diff --quiet HEAD^ HEAD -- . ':(exclude).github' ':(exclude).agents' ':(exclude).amp' ':(exclude).vscode' ':(exclude)AGENTS.md' ':(exclude)README.md' ':(exclude).gitignore' ':(exclude)cspell*'" }