Cloudflare Workers
On Cloudflare a Worker serves the API, the editor, and the server's own pages, a Durable Object for each document runs its collaboration rooms, Hyperdrive connects to PostgreSQL, and a Cron Trigger every five minutes runs cleanup and retries email. packages/cloud/deploy/cloudflare is the deployment to copy: a Wrangler configuration and the Worker's entry, which reads openpencil-cloud.toml from the same folder.
- Copy the folder beside it, for example to
packages/cloud/deploy/mine, so the Worker's entry still reaches the runtime. - Create a Hyperdrive configuration for the database with
wrangler hyperdrive create, and put its ID, your domain, and a Worker name in the copy'swrangler.jsonc. - Add your TOML as
openpencil-cloud.tomlin the copy; Wrangler bundles it as text. Leave[database]empty, sinceDATABASE_URLcomes from Hyperdrive, and trustcf-connecting-ipunder[authentication.trusted_proxies]. - Migrate from a checkout, with that TOML as
OPENPENCIL_CLOUD_CONFIGand a direct connection string asDATABASE_URL:bun --filter @open-pencil/cloud migrate. The Worker never migrates, so do this before every deploy. - Build the site with
bun run build:packages && bun run build:cloud, then deploy from the copy withbunx wrangler deploy --assets "$(git rev-parse --show-toplevel)/dist-cloud" --secrets-file secrets.json, wheresecrets.jsonholds the secrets the TOML names.
To run collaboration rooms in one region, name a Durable Object jurisdiction in the Worker's entry: createCloudflareCloud(config, { relayJurisdiction: 'eu' }). Rooms save their updates and snapshots to the database and bucket, so put those in the same region too. Set it before the first room opens, since rooms named in a jurisdiction are other objects than those named outside one.
The operator commands work the same way, from a checkout with a direct connection. The [workers] intervals don't apply: mail a request queues is sent when the request finishes, and the Cron Trigger handles the rest.