Move from Cloudflare R2 or Pages
This guide is for static sites and single-page apps (SPAs) that you serve from Cloudflare today. That includes:
- Vite, React, Vue, or Svelte builds uploaded to Cloudflare R2 and served by a Worker.
- Projects connected to Cloudflare Pages that only serve built files.
- Apps from Lovable, Bolt, or v0 that build to plain files. A Vite and React project is detected as React + Vite.
If your app runs code on Cloudflare, it does not move as is. See What does not move.
Moving from Vercel? See Move from Vercel.
How the pieces map
Section titled “How the pieces map”| Cloudflare | LeafCloud |
|---|---|
| One folder of files per project in R2 | One site, created with leaf sites create <name> |
| One Pages project | One site |
Worker or Pages routing for about/index.html | Directory index: /about redirects to /about/, which serves about/index.html |
Worker fallback to index.html for client-side routes | not_found = "spa:index.html" in leaf.toml. The page is served with status 200. |
| Worker or Pages custom 404 page | not_found = "page:404.html" in leaf.toml. The page is served with status 404. |
| Pages build command and build output directory | Framework detection, or build and dir in leaf.toml, or --dir on the command line |
| Pages build environment variables | The environment of the shell that runs leaf deploy. Variables that start with LEAF_ are removed before the build runs. |
| Pages deployment history and rollback | leaf deploys and leaf rollback |
Without a not_found setting, a missing path returns a plain 404. LeafCloud does not fall back to index.html unless you set spa:.
Before you start
Section titled “Before you start”Check that your project can be built as a static site. Next.js must use output: 'export'. Projects with API routes, middleware, or server rendering cannot deploy. See Troubleshooting.
Install the CLI and sign in:
leaf loginSee Install the CLI and Sign in.
Step 1: Deploy one project
Section titled “Step 1: Deploy one project”Pick one project and run a dry run from its folder. The dry run builds nothing and uploads nothing.
cd my-appleaf deploy --dry-runCreate the site, then add a leaf.toml file. For an SPA, include the not_found line:
leaf sites create my-appsite = "my-app"not_found = "spa:index.html"Deploy:
leaf deployIf you already built the project on Cloudflare, or you have a folder of built files, deploy that folder and skip the build:
leaf deploy --no-build --dir distStep 2: Check the site
Section titled “Step 2: Check the site”Open https://my-app.leafcloud.app and check these:
- The home page loads.
- A client-side route, such as
/settings, loads the app and does not show a 404. - A missing file, such as
/no-such-file.png, returns a 404. - A folder with an
index.htmlfile, such as/about, redirects to/about/.
Check the deploy history:
leaf deploys --site my-appStep 3: Deploy the other projects
Section titled “Step 3: Deploy the other projects”Each project folder needs its own leaf.toml with its site name. Run a loop over the folders in a shell script:
for dir in ~/projects/static-sites/*/; do (cd "$dir" && leaf deploy --yes --json) || echo "failed: $dir"done--yes trusts each project’s build and install scripts. Only run this on code you trust. Run it from a machine that has a LEAF_TOKEN or a saved login.
Two default limits matter here: 5 sites per account and 100 deploys per day. See Limits that apply.
Move user uploads from R2
Section titled “Move user uploads from R2”If members upload one .html file or a .zip of a site to R2 and a Worker serves it, the Worker is only doing three jobs: serving index.html, falling back to it for client-side routes, and returning a 404 page. The archive endpoint does all three, so you can drop the Worker.
Keep the bucket read-only for the import, and keep the old Worker running until the last step.
-
List the objects. With the AWS CLI:
TerminalTerminal windowbash # R2_ENDPOINT is the S3 API endpoint shown in your R2 bucket settings.R2_ENDPOINT=... AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY=... \aws s3 ls s3://UPLOADS --recursive --region auto \--endpoint-url "$R2_ENDPOINT"Or with
rclone:TerminalTerminal windowbash rclone lsf r2:UPLOADS --recursive -
Import one object per call. Download the object and send it to the archive endpoint. Use
text/htmlfor an.htmlfile andapplication/zipfor a.zip. Prefix member names because site names are unique across the whole platform:TerminalTerminal windowbash curl -fsS -X POST "https://api.leafcloud.in/v1/sites/acme-$MEMBER/deploys/archive?label=$MEMBER" \-H "Authorization: Bearer $LEAF_TOKEN" \-H "Content-Type: $CONTENT_TYPE" \-H "Idempotency-Key: r2-$KEY" \--data-binary "@$FILE"labelmakes the member’s address<member>.sites.example.appon your project-addresses domain. It is used when the site is created. Run two or three uploads at a time, not the whole bucket at once: the API runs two archive uploads at once by default. When a call returns429 archive_busy, wait forRetry-Afterseconds, then retry the same object with the sameIdempotency-Key. A 429 created nothing.The endpoint serves
index.htmlat/and detects a single-page app whenindex.htmlloads a JavaScript bundle and there is no other HTML page. If the Worker always servedindex.htmlfor unknown paths, add¬_found=spa:index.htmlto the call. For a custom 404 page, use¬_found=page:404.htmland include that file in the upload. -
Check each site. Every member site answers at
https://acme-$MEMBER.leafcloud.appbefore you change any DNS. Open the home page, a client-side route, and a missing file. See Host your users’ projects for the zip layout and the response fields. -
Move the wildcard record last. Add your project-addresses domain, such as
sites.example.app, withleaf domains add sites.example.app --project-addresses --all-projects, or with the API and"kind": "platform". Create the wildcard*.sites.example.apprecord it prints, DNS only (grey cloud), and wait until the domain is live. Then point the old wildcard record at the same target and remove the R2 Worker. Until this step, members keep using the old address. After it, their sites are already live, so the move is only a DNS change.
See Project addresses, Records to add, Domain limits, and Pricing and limits. The full backend flow is in Host your users’ projects and the Deploy API.
Step 4: Switch traffic
Section titled “Step 4: Switch traffic”Your sites live at <name>.leafcloud.app. Update the places that point to the old Cloudflare address, such as links, sitemaps, and OAuth redirect URLs, to the new address.
To keep your own domain and move it to LeafCloud, keep DNS at Cloudflare and follow this order. The domain keeps answering while you go through it.
-
Deploy and check the site, as in steps 1 and 2.
-
Add the domain to the site. For a bare domain and
www, the command adds both:TerminalTerminal windowbash leaf domains add shop.example.com --project my-app -
Add the records at Cloudflare, with the proxy off. Create the TXT and
_acme-challengerecords, and the CNAME to the target thatleaf domains show shop.example.comprints. Every LeafCloud record must be DNS only (the grey cloud). A proxied record gives visitors Cloudflare error 525. If Cloudflare Pages already created a record for the host, change its target to the LeafCloud target, and set it to DNS only. -
Wait for Live. Run
leaf domains check shop.example.com --wait, and do not go on until it exits with0. -
Remove the Pages custom domain only after the domain is live. Removing it before then can leave the host with no working site.
-
Check the domain in a browser, and with
leaf domains show shop.example.com.
Cloudflare’s dashboard labels and the way Pages manages its own records may differ from these steps. Confirm each one in Cloudflare’s documentation before you change production DNS. For the records and the states, see Records to add and Status and checks. The Cloudflare DNS page has the Cloudflare steps.
Keep the Cloudflare copy of the files, or the Pages project, until each site has passed your checks.
Step 5: Roll back
Section titled “Step 5: Roll back”To go back to the deploy before the current one:
leaf rollback --site my-appTo go back to a specific deploy, pass its ID from leaf deploys --site my-app:
leaf rollback <deploy_id> --site my-appOnly deploys that LeafCloud keeps can be rollback targets. By default it keeps the last 5 deploys of each site. See Deploy history and rollback.
What does not move
Section titled “What does not move”These Cloudflare features have no LeafCloud equivalent:
- Workers code. Any logic that runs in a Worker, including request handlers, auth checks, and A/B tests, must move to your own backend or into the client.
- Pages Functions. The
functions/folder is not run. - KV, D1, Durable Objects, and Queues. Store data with a service you run or a third-party provider.
- R2 access from apps. Browser or server code that reads from or writes to R2 needs another service.
- Redirect and header files.
_redirectsand_headersare not read. Usepage:andspa:for fallback pages. - Server-side rendering. LeafCloud serves files that already exist after the build.
Your own domain moves with the steps in Step 4, and the domain’s details are in Custom domains.
Limits that apply
Section titled “Limits that apply”These are the default limits for a new account. To raise them, send a request from Settings → Help & feedback in the dashboard.
| Limit | Default |
|---|---|
| Sites per account | 5 |
| Deploys per day | 100. The count resets at midnight UTC. |
| Files per deploy | 5,000 |
| Size of one file | 25 MB |
| Space for kept deploys | 250 MB |
| Deploys kept per site | 5 |
For pricing and fair use, see Pricing and limits.