Host on Cloudflare
Cloudflare runs the app as WebAssembly on its edge, as a Worker (cloudflare) or on Pages (pages).
Build
rustup target add wasm32-unknown-unknown # once
wisp build --target cloudflare # Workers: dist/cloudflare
wisp build --target pages # Pages: dist/pages
--out <folder> changes the folder. No wasm-bindgen or other tool is needed. In Cloudflare's CI a plain wisp build picks the target from WORKERS_CI or CF_PAGES.
Deploy
Workers, from dist/cloudflare:
npx wrangler deploy
npx wrangler secret put WISP_SECRET
Pages, from dist/pages (_worker.js and _routes.json):
npx wrangler pages deploy .
For Workers, wisp deploy init cloudflare writes a GitHub Actions workflow that builds and deploys on push to main; it reads the secrets CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID.
Environment
WISP_SECRET: a Worker secret (above), or on Pages under Settings.- Read other values with
wisp::env("KEY");std::env::varsees nothing and there is no.env. CRON_SECRET, if the app haswisp::cron: set it as a secret; the cron triggers send it.WISP_STORE=d1:DBand the rest: Environment variables.
Limits
- No threads, sockets or files: use
wisp::spawnandwisp::sleep, nottokio::spawn. See What works on the edge. - WebSockets answer 501; use
Response::events(SSE).Response::streamandResponse::eventsare live. wisp::channel,wisp::everyandRateLimitare not in the edge build.- Started timers and fetches keep the instance alive (
waitUntil). - Cron:
wisp::cronbecomes[triggers] cronsinwrangler.toml(Workers); Pages has no trigger, so the build says so and stops.
Files and Data
static/goes into the build output and is served by Cloudflare before the app runs (Workers:publicwith an[assets]entry inwrangler.toml; Pages: beside_worker.js).Table::savedandRestare per-instance memory unlessWISP_STORE=d1:DBis set, with a[[d1_databases]]binding namedDBinwrangler.toml. See Saved tables.
More
Edge and serverless targets, Deploying.
Is This Page Useful?