Repository navigation
Setting up Cloudflare
CraftPages publishes your site to Cloudflare as a Worker with static assets: Cloudflare serves your files from its network. Serving static files is free, including on the free plan. You need three things: a Cloudflare account, its Account ID and an API token. This takes about five minutes, once.
Sign up at dash.cloudflare.com/sign-up and confirm your email. The free plan is enough.
The first time you open Workers & Pages, Cloudflare asks you to choose a
workers.dev subdomain (e.g. my-studio). Sites will first be reachable at
site-name.my-studio.workers.dev; you can add your own domain later (step 6).
Setting up a site for a client? Create the account in their name (or have them do it), so the site and the token belong to them. See Working with others.
Any of these works:
- Open Workers & Pages in the dashboard. The Account ID is in the right-hand column, under Account details, with a copy button.
- Or click the ⋯ menu next to your account name on the account home page and choose Copy account ID.
- Or look at the address bar: in
https://dash.cloudflare.com/0123abcd…/home, the 32 characters afterdash.cloudflare.com/are the Account ID.
It looks like 0123456789abcdef0123456789abcdef. It isn't secret.
- In the dashboard, click the person icon (top right) → My Profile → API Tokens, or go to dash.cloudflare.com/profile/api-tokens.
- Click Create Token, then Create Custom Token → Get started.
-
Token name: something you'll recognise, e.g.
CraftPages. - Permissions: one row: Account · Workers Scripts · Edit. To also use Sync between computers (beta), add a second row: Account · Workers R2 Storage · Edit.
- Account Resources: Include · your account (the one from step 2).
- Leave Zone Resources, Client IP Address Filtering and TTL as they are.
- Click Continue to summary, then Create Token.
- Copy the token now. Cloudflare shows it only once. If you lose it, roll it or create a new one.
The token is a password for publishing: anyone who has it can change the Workers in that account. Don't email it or put it in the site folder. CraftPages keeps it in your system keychain.
A token can't be limited to one Worker. If you publish sites for several clients, give each client their own Cloudflare account and token rather than sharing yours.
- App settings → Deploy connections → Add connection…
-
Name: e.g.
My CloudflareorAcme (client). - Account ID and API token: paste them.
- Save. CraftPages tests the token right away and says how many Workers it sees. If it says the token can't publish Workers, check the permission in step 3.
You can add several connections (yours, each client's). Each project picks one.
- Open the site, then Project settings → Deploy.
- Connection: the one from step 4.
-
Worker: type a new name (e.g.
acme-site, lowercase, dashes allowed) or click List Workers to pick an existing one. A new Worker is created on the first publish. Workers that run their own code aren't offered, so CraftPages never replaces an app. - Save, then Publish site.
The site is live at https://acme-site.my-studio.workers.dev within a few seconds.
Your domain has to use Cloudflare's DNS (Cloudflare → Add a domain, then change the nameservers at your registrar as shown).
- Workers & Pages → your Worker → Settings → Domains & Routes → Add → Custom domain.
- Enter
www.example.com(and/orexample.com) and confirm. Cloudflare creates the DNS record and the certificate. - To send
example.comtowww.example.com(or the other way round), add a Redirect Rule in the domain's Rules section.
A site deployed with wrangler deploy (assets only, no Worker script) can be published from
CraftPages: pick the same Worker name in step 5. The first publish shows a warning that the
live version came from somewhere else; that is expected (see Working with others).