If acme.com is a Next.js app on Vercel, a middleware.ts rewrite forwards
/docs/* to your NookDocs origin. See Host at a subpath for
the overall model.
middleware.ts
Add this to your Next.js app (replace origin/domain/path):
// middleware.ts
import { NextResponse } from "next/server";
export const config = { matcher: "/docs/:path*" };
export function middleware(request: Request) {
const url = new URL(request.url);
url.hostname = "acme.nookdocs.site";
url.protocol = "https:";
url.port = "";
const headers = new Headers(request.headers);
headers.set("X-Nookdocs-Host", "acme.com");
headers.set("X-Nookdocs-Base-Path", "/docs");
return NextResponse.rewrite(url, { request: { headers } });
}Grab the snippet pre-filled with your origin/domain/path from Settings → Domains → Show proxy setup.
Why middleware, not rewrites
vercel.json / next.config.js rewrites can forward the path but can't set
request headers, and we need X-Nookdocs-Host + X-Nookdocs-Base-Path.
Middleware's NextResponse.rewrite(url, { request: { headers } }) does both —
it proxies to the external origin and attaches the headers.
Verify
curl -sI https://acme.com/docs | grep -i content-type
curl -s https://acme.com/docs/llms.txt | head -1Notes
The
matcherscopes the middleware to/docs/*only — the rest of your app is untouched.Not a Next.js app? Use Cloudflare Workers or AWS CloudFront in front of any stack.
Sending a CSP? See CSP configuration.