Skip to content

chore: serve the site from Cloudflare Workers - #420

Merged
brunobuddy merged 1 commit into
mainfrom
chore/cloudflare-workers
Oct 19, 2026
Merged

brunobuddy merged 1 commit into
mainfrom
chore/cloudflare-workers

Conversation

@brunobuddy

Copy link
Copy Markdown
Member

What changed

  • wrangler.jsonc: Worker modelparams-dev, nodejs_compat, assets from dist/, run_worker_first: true, html_handling: drop-trailing-slash (Vercel's cleanUrls + trailingSlash: false), not_found_handling: 404-page.
  • worker/index.ts: Worker entry.
    • modelparameters.dev, www.modelparameters.dev, www.modelparams.dev → 308 to https://modelparams.dev (same path and query), as today.
    • /mcp and /api/mcp → api/mcp.ts; /api/v1/validate → api/v1/validate.ts. Both are the existing fetch handlers, unchanged.
    • The vercel.json headers: catalog Cache-Control, CORS and X-Robots-Tag: noindex on /api/v1/*, text/plain + CORS on llms.txt / llms-full.txt.
    • The asset layer answers clean-URL redirects (/api.html, /api/) with 307; the Worker makes them 308 like Vercel.
    • Unknown /api/* paths answer a JSON 404.
  • Usage tracking: Vercel Web Analytics can't come along. The Worker logs one JSON line per API/MCP/llms.txt request ({"event":"api_request","endpoint":…}, same classification as src/tracking/api-usage.ts) to Workers Logs. There's no dashboard for it.
  • api/mcp.ts: server version falls back to COMMIT_SHA (the deploy script passes WORKERS_CI_COMMIT_SHA).
  • vercel.json, middleware.ts and api/ stay as they are, so Vercel keeps deploying until DNS moves.
  • tests/worker.test.ts (11 tests), worker/ added to the API typecheck, wrangler dev dependency, cf:dev / deploy scripts, docs.

How it was verified

  • npm run lint, npm run typecheck, npm test (282 tests) pass. wrangler deploy --dry-run: 2204 assets, Worker 259 KiB gzipped.
  • npm run build + wrangler dev, compared with production:
    • Same status, type and size: /, /api, /glossary, /mcp-server, /models/openai/gpt-3.5-turbo-0125, /providers/openai, /parameters/temperature, /llms.txt, /llms-full.txt, /robots.txt, /sitemap.xml, /404, assets.
    • Same 308 target: /index, /index.html, /api/, /api.html, /models/…/x.html, /models/…/x/, /404.html.
    • /api/v1/*.json: same body, Content-Type, Cache-Control, CORS and X-Robots-Tag headers.
  • /api/v1/validate: GET usage, valid params, out-of-range params, unknown model, bad JSON, empty body and PUT all gave the same body as production (matching md5 where checked). OPTIONS → 204 with CORS.
  • /mcp: raw JSON-RPC initialize → notifications/initialized (202) → tools/list (4 tools) → tools/call. The MCP SDK's StreamableHTTPClientTransport client did connect + listTools + callTool against wrangler dev and against production, with the same results. GET with Accept: text/event-stream → 405, as in prod.
  • With a Host: override, all three alias hosts → 308 to https://modelparams.dev/…?x=1.

Behaviour differences

  • Unknown pages: production currently answers /nope (and /models/openai) with 200 and the home page, even though the build emits a branded 404.html meant for that case. The Worker serves 404.html with status 404. To keep today's soft-200, set not_found_handling to single-page-application.
  • Unknown /api/v1/*.json gives a JSON 404 instead of Vercel's plain-text one.
  • /assets/*.js is served as text/javascript instead of application/javascript.
  • No Vercel Web Analytics custom events for API usage; they're log lines now.

Cloudflare Workers Builds settings

  • Root directory: /
  • Build command: npm run build
  • Deploy command: npm run deploy (wrangler deploy --var COMMIT_SHA:$WORKERS_CI_COMMIT_SHA)
  • Build env vars: none required (Node ≥ 20)

Secrets / vars

  • No secrets.
  • COMMIT_SHA is set by the deploy script.
  • Routes/custom domains: modelparams.dev, www.modelparams.dev, modelparameters.dev, www.modelparameters.dev, all to this Worker. The redirects are in the Worker.

Add a Worker (worker/index.ts, wrangler.jsonc) that serves dist/ as static
assets and routes /mcp, /api/mcp and /api/v1/validate to the existing fetch
handlers in api/. It also carries what vercel.json and middleware.ts did:
the /api and llms.txt headers, 308s for clean URLs, and the redirect from
modelparameters.dev and the www hosts to modelparams.dev.

API usage is logged as a JSON line instead of sent to Vercel Analytics.
The MCP server reads its version from COMMIT_SHA when not on Vercel.
vercel.json and middleware.ts stay, so Vercel keeps working until DNS moves.
@vercel

vercel Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
modelparams.dev Ready Ready Preview Oct 19, 2026 6:54am UTC

Request Review

@github-actions github-actions Bot added site Website code or tooling meta Repo docs, CI, and config labels Oct 19, 2026
@brunobuddy
brunobuddy merged commit 6efb845 into main Oct 19, 2026
13 checks passed

This branch was successfully deployed

1 active deployment
Preview — 23134067 Deployed Oct 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

meta Repo docs, CI, and config site Website code or tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant