Skip to main content

Host at a subpath

Cloudflare Workers

Host your NookDocs site at yourdomain.com/docs with a Cloudflare Worker reverse proxy.

If acme.com is on Cloudflare, a small Worker forwards /docs/* to your NookDocs origin. See Host at a subpath for the overall model.

Subpath hosting is configured entirely in the customer's Cloudflare Worker — there is no NookDocs API for it. The Worker matches /docs and /docs/*, rewrites the request to the project origin (<slug>.nookdocs.site), and sets two request headers: X-Nookdocs-Host (the public host, e.g. acme.com) and X-Nookdocs-Base-Path (e.g. /docs). NookDocs then prefixes every emitted link, asset, and canonical URL with that base path. Use redirect: "manual" in the fetch call so NookDocs trailing-slash and config redirects reach the visitor intact.

1. Create the Worker

In the Cloudflare dashboard → Workers & Pages → Create → Worker, paste this (replace the origin with your project's subdomain and adjust the path):

export default {
  async fetch(request) {
    const url = new URL(request.url);
    // Only proxy the docs subpath; everything else hits your own origin.
    if (url.pathname === "/docs" || url.pathname.startsWith("/docs/")) {
      const target = new URL(request.url);
      target.hostname = "acme.nookdocs.site";
      target.protocol = "https:";
      target.port = "";
      const headers = new Headers(request.headers);
      headers.set("X-Nookdocs-Host", "acme.com");
      headers.set("X-Nookdocs-Base-Path", "/docs");
      headers.set("Host", "acme.nookdocs.site");
      return fetch(target, {
        method: request.method,
        headers,
        body: request.body,
        redirect: "manual",
      });
    }
    return fetch(request);
  },
};

The dashboard generates this snippet with your exact origin, domain, and path pre-filled — Settings → Domains → Show proxy setup. Copy from there.

2. Add a route

Workers → your worker → Settings → Domains & Routes → Add route:

Route:  acme.com/docs*
Zone:   acme.com

The * is important — it matches /docs and everything beneath it.

3. Verify

curl -sI https://acme.com/docs | grep -i content-type   # text/html from NookDocs
curl -s  https://acme.com/docs/llms.txt | head -1        # # Your Project

Internal links, assets, and canonical tags all resolve under acme.com/docs.

Notes

  • Other paths are untouchedreturn fetch(request) passes everything outside /docs/* straight to your own origin.

  • Redirects use redirect: "manual" so NookDocs redirects (trailing-slash, config redirects) reach the visitor intact.

  • If you send a CSP from your site, see CSP configuration.

Was this page helpful?

Last updated August 11, 2026