Skip to content

fix(deploy): answer CORS preflight OPTIONS from a worker script#194

Merged
MaximusHaximus merged 1 commit into
masterfrom
fix/cors-preflight-worker
Jul 9, 2026
Merged

fix(deploy): answer CORS preflight OPTIONS from a worker script#194
MaximusHaximus merged 1 commit into
masterfrom
fix/cors-preflight-worker

Conversation

@MaximusHaximus

@MaximusHaximus MaximusHaximus commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Problem

The static-assets layer serves GET/HEAD only and returns 405 to every other method — including the preflight OPTIONS browsers send before a GET that carries a Content-Type header. maticjs sends that header when fetching /network/<network>/<version>/index.json, so the failed preflight blocks the request and client initialisation fails in every browser. The previous nginx origin answered OPTIONS with 204 and allowed Content-Type/Authorization.

Fix

A minimal worker entry (worker/worker.ts) answers OPTIONS with 204 and the CORS preflight headers, and delegates everything else to the assets binding — _headers and not_found_handling still apply, so GET behaviour is unchanged.

run_worker_first = true is required: with default routing the asset layer answers OPTIONS on asset-matched paths itself (405) before the worker runs (verified with wrangler dev).

Supporting changes: main + ASSETS binding in wrangler.toml, worker/tsconfig.json plus the @cloudflare/workers-types devDep, tsconfigRootDir in eslint.config.js (the repo now has two tsconfig roots), and doc touch-ups.

Verification (local wrangler dev)

Request Result
OPTIONS /network/mainnet/v1/index.json (Access-Control-Request-Headers: content-type) 204 + full preflight header set
GET /network/mainnet/v1/index.json 200, _headers CORS + Cache-Control intact
GET / 200
GET /network/nope/v1/index.json 404

Deploy notes

Merge auto-deploys staging; production is a manual workflow_dispatch of deploy.yml.

https://claude.ai/code/session_019bL7UgsRRhAC15kxdH3q2y

The Cloudflare asset layer serves GET/HEAD only and returns 405 to every
other method — including the OPTIONS preflights browsers send because
maticjs attaches Content-Type to its GETs of /network/.../index.json. A
failed preflight blocks the GET, so since the Jul 8 DNS swap every
browser consumer of maticjs (staking-ui My Account + write flows,
portal bridge flows, third-party apps) fails at StakingClient.init().

Add a minimal worker entry that answers OPTIONS with 204 and the
allow-headers the old nginx origin advertised (Content-Type,
Authorization), delegating everything else to the assets binding.
run_worker_first is required: verified with wrangler dev that without
it the asset layer 405s OPTIONS on asset-matched paths before the
worker runs. Also corrects the _headers comment that called the
allow-headers cargo-cult — maticjs genuinely needs them.

Verified locally via wrangler dev: OPTIONS → 204 with full preflight
headers; asset GET → 200 with _headers CORS + Cache-Control intact;
missing path → 404.

Claude-Session: https://claude.ai/code/session_019bL7UgsRRhAC15kxdH3q2y
@sonarqubecloud

sonarqubecloud Bot commented Jul 9, 2026

Copy link
Copy Markdown

@MaximusHaximus
MaximusHaximus marked this pull request as ready for review July 9, 2026 08:37
@MaximusHaximus
MaximusHaximus requested a review from a team as a code owner July 9, 2026 08:37
@MaximusHaximus
MaximusHaximus merged commit 79595e6 into master Jul 9, 2026
9 checks passed
@MaximusHaximus
MaximusHaximus deleted the fix/cors-preflight-worker branch July 9, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant