Skip to main content

Host at a subpath

Vercel

Host your NookDocs site at yourdomain.com/docs with Vercel middleware.

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.

This is configured in the customer's own Next.js middleware.ts — there is no NookDocs API for subpath hosting. Use NextResponse.rewrite(url, { request: { headers } }), not vercel.json/next.config.js rewrites, because only middleware can attach request headers. Rewrite to the project origin (<slug>.nookdocs.site) and set X-Nookdocs-Host (public host) and X-Nookdocs-Base-Path (e.g. /docs); NookDocs prefixes every link, asset, and canonical with that base path. Scope it with export const config = { matcher: "/docs/:path*" } so the rest of the app is untouched.

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 -1

Notes

Was this page helpful?

Last updated August 11, 2026