Repository navigation
chore: serve the site from Cloudflare Workers - #420
Merged
Merged
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
wrangler.jsonc: Workermodelparams-dev,nodejs_compat, assets fromdist/,run_worker_first: true,html_handling: drop-trailing-slash(Vercel'scleanUrls+trailingSlash: false),not_found_handling: 404-page.worker/index.ts: Worker entry.modelparameters.dev,www.modelparameters.dev,www.modelparams.dev→308tohttps://modelparams.dev(same path and query), as today./mcpand/api/mcp→api/mcp.ts;/api/v1/validate→api/v1/validate.ts. Both are the existing fetch handlers, unchanged.vercel.jsonheaders: catalogCache-Control, CORS andX-Robots-Tag: noindexon/api/v1/*,text/plain+ CORS onllms.txt/llms-full.txt./api.html,/api/) with 307; the Worker makes them 308 like Vercel./api/*paths answer a JSON 404.{"event":"api_request","endpoint":…}, same classification assrc/tracking/api-usage.ts) to Workers Logs. There's no dashboard for it.api/mcp.ts: server version falls back toCOMMIT_SHA(the deploy script passesWORKERS_CI_COMMIT_SHA).vercel.json,middleware.tsandapi/stay as they are, so Vercel keeps deploying until DNS moves.tests/worker.test.ts(11 tests),worker/added to the API typecheck,wranglerdev dependency,cf:dev/deployscripts, 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:/,/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./index,/index.html,/api/,/api.html,/models/…/x.html,/models/…/x/,/404.html./api/v1/*.json: same body,Content-Type,Cache-Control, CORS andX-Robots-Tagheaders./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-RPCinitialize→notifications/initialized(202) →tools/list(4 tools) →tools/call. The MCP SDK'sStreamableHTTPClientTransportclient did connect +listTools+callToolagainstwrangler devand against production, with the same results. GET withAccept: text/event-stream→ 405, as in prod.Host:override, all three alias hosts → 308 tohttps://modelparams.dev/…?x=1.Behaviour differences
/nope(and/models/openai) with 200 and the home page, even though the build emits a branded404.htmlmeant for that case. The Worker serves404.htmlwith status 404. To keep today's soft-200, setnot_found_handlingtosingle-page-application./api/v1/*.jsongives a JSON 404 instead of Vercel's plain-text one./assets/*.jsis served astext/javascriptinstead ofapplication/javascript.Cloudflare Workers Builds settings
/npm run buildnpm run deploy(wrangler deploy --var COMMIT_SHA:$WORKERS_CI_COMMIT_SHA)Secrets / vars
COMMIT_SHAis set by the deploy script.modelparams.dev,www.modelparams.dev,modelparameters.dev,www.modelparameters.dev, all to this Worker. The redirects are in the Worker.