Cloudflare Workers
A Worker with static assets serves the built site and answers the annotation API on the same origin. A complete example is in examples/cloudflare-worker.
import { createAnnotationsHandler, github } from 'starlight-annotations/server';
export default { async fetch(request, env) { if (new URL(request.url).pathname.startsWith('/_annotations/')) { const options = { repo: env.ANNOTATIONS_REPO, token: env.GITHUB_TOKEN, clientId: env.GITHUB_CLIENT_ID, clientSecret: env.GITHUB_CLIENT_SECRET, sessionSecret: env.ANNOTATIONS_SECRET, }; // Until every value is set, answer 503: the pages then hide the annotation UI. if (Object.values(options).some((value) => !value)) { return Response.json({ error: 'Annotations are not configured.' }, { status: 503 }); } const response = await createAnnotationsHandler(github(options))(request); if (response) return response; } return env.ASSETS.fetch(request); },};{ "name": "my-docs", "main": "./worker.js", "compatibility_date": "2026-10-29", "assets": { "directory": "./dist", "binding": "ASSETS", "run_worker_first": ["/_annotations/*"] }, "vars": { "ANNOTATIONS_REPO": "owner/docs", "GITHUB_CLIENT_ID": "Ov23…" }}run_worker_first sends only the API paths to the Worker; pages and assets are served directly.
Set the secrets once:
npx wrangler secret put GITHUB_CLIENT_SECRETnpx wrangler secret put GITHUB_TOKENopenssl rand -hex 32 | npx wrangler secret put ANNOTATIONS_SECRETThen npm run build && npx wrangler deploy. The OAuth app, the token and the session secret are explained step by step in Store notes on GitHub.
A site behind a password
Section titled “A site behind a password”If your Worker already checks a password or Cloudflare Access, call the handler after that check: notes are then readable only by people who can read the pages.