deploy-cloudflare
This page shows how to add files for hosting on Cloudflare Workers. It is optional, and it is one way among several. The Deploy overview compares the others, and the Cloudflare guide shows the same setup written by hand.
What you get
Every file is ordinary code that you own. Edit or delete any of them.
- A
wrangler.jsoncin the shell and in each remote. Each app is its own Worker with static assets, with astagingand aprodenvironment. Only the shell has the single-page fallback. - A
public/_headersin each of those apps. It holds the cache rules, and on remotes the CORS header. deploy/cloudflare.json, where you write the address of each environment.scripts/deploy-cloudflare.tsand the scriptpnpm deploy:cloudflare.docs/cloudflare.md, a guide written for your project.- With
ci-github, adeploy-cloudflare.ymlworkflow. wrangleras a dev dependency.
When to use it
Use it when you want static hosting on Cloudflare and would rather start from working files than write them. If you host somewhere else, or already have your own pipeline, skip it.
Add it
What changed:
Add ci-github first if you want the workflow. A remote added later gets its own two files.
Use it
Put the real addresses in deploy/cloudflare.json. The script stops on an empty address or an example.com one.
Then build once and deploy an environment:
You should see a line such as staged shell for prod: apps/shell/.mfeflow/cloudflare/prod for each app. The build is not repeated for another environment. The script copies each dist and changes only the copy: it picks runtime-config.<env>.json, writes registry/index.json, and puts the shell's address into each remote's CORS header.
Configure
How it works
The shell and each remote are separate Workers on separate origins, so remotes are loaded across origins. That is why remotes answer with Access-Control-Allow-Origin and why the script adds their origins to registryOrigins. Cloudflare makes one Worker per environment, with its own name. Bindings and vars are not inherited by an environment, so the R2 option repeats them in each block.
The workflow builds once, uploads the dist folders, and deploys each app and environment as one job of a matrix with cloudflare/wrangler-action. A push to main deploys staging. A manual run can choose prod.
Gotchas
- The workflow needs the secrets
CLOUDFLARE_API_TOKENandCLOUDFLARE_ACCOUNT_IDon the GitHub environmentscloudflare-stagingandcloudflare-prod. _headersdoes not apply to responses a Worker makes. The R2 proxy sets its ownCache-Control.- New projects list
workerd: falseunderallowBuildsinpnpm-workspace.yaml. In an older project, add that line before you install wrangler, or pnpm 11 stops withERR_PNPM_IGNORED_BUILDS. Wrangler deploys without that install script. - Each environment has one shell address, because a remote sends a single
Access-Control-Allow-Origin. - A remote's build must keep
public/_headers. The script stops if the staged remote has none, because the shell could not load it. - Adding a remote means adding its address to each environment in
deploy/cloudflare.json. The script says so when it is missing. - Remove the feature by deleting these files and running
pnpm remove wrangler.