Deploy: a site on Cloudflare, with sign-in and content
For a site made from a cloudflare:* template. Sign in to Cloudflare once: mise x -- pnpm dlx wrangler login. Every task here is safe to run again.
The first time
- Name the Worker, database and bucket in
site/wrangler.jsonc, and setLIVE_URLandADMIN_EMAILunder[env]inmise.toml. mise run signin:access: Cloudflare Access in front of the admin. It prints the lines to put inastro.config.mjsandwrangler.jsonc; put them in.mise run live:ship: check, deploy, wait for the new version to answer.mise run signin:token -- --live: the CLI is an administrator of the deployed site.- Bring the content. A newly deployed site has none:
mise run emdash -- site export --output site.emdash # this machine's content
mise run emdash -- site import site.emdash --analyze --live # prints a plan and its digest
mise run emdash -- site import site.emdash --plan <digest> --confirm --live
These three are EmDash’s own site export and site import, as live:ship prints them for a site with no home page. No test step runs them.
site:seed and site:demo do not fill a deployed site: This machine or deployed.
After that
mise run live:ship # deploy again
mise run live:logs # follow its log
mise run live:undo # back to the previous version (code only)
mise run live:backup # a database bookmark to restore to, and a content package
mise run content:pull # the deployed content, as a package in site/backups/
The token signin:access needs
Everything uses the wrangler login except signin:access: that login can read Cloudflare Access but not change it. Make an API token in the Cloudflare dashboard (My Profile, API Tokens) with Access: Apps and Policies, Edit and Access: Service Tokens, Edit, and give it to the task in CLOUDFLARE_API_TOKEN. With fnox in your [tools] the task reads it from there by itself:
fnox init # if this machine has no fnox config yet
fnox set CLOUDFLARE_API_TOKEN # it asks for the value
A domain of its own, and the zone’s settings
A workers.dev address is in no zone of yours. To give the site a domain in a zone on your account, add it to routes in site/wrangler.jsonc, set LIVE_URL to it, and deploy:
"routes": [{ "pattern": "www.example.com", "custom_domain": true }],
Then mise run signin:access again: it puts the site’s Access application (the one whose audience is CF_ACCESS_AUDIENCE in wrangler.jsonc) over the new address as well, and its media and plugin routes stay public there too. A second application would have another audience, which the site does not accept. And mise run live:zone sets the zone as Coywolf runs its sites (Plugins). It needs a token of its own, as signin:access does: Zone → Zone Settings → Edit and Zone → Zone WAF → Edit, in CLOUDFLARE_API_TOKEN or fnox.
Limits
signin:accesscovers/_emdashonly: the site’s pages stay public, and so do uploaded media and the addresses a plugin opens to visitors.live:undorolls back code, not content. For content:live:backupbefore a risky change.- A deployed site with the plugin sandbox on needs the Workers Paid plan.
- The deploying tasks are tested by the live group, which deploys to a Worker kept for it and is run by name (How to help).