Cloudflare
On Cloudflare, your Astro site runs as a Worker, and the CMS runs in a Durable Object next to it. This page sets up the object, media, email and secrets, and deploys the site.
How it runs
The CMS lives in one Durable Object, with its own SQLite database. Every request to /_tenon and every read from a page goes to that object. Its alarm is also the job clock: it wakes when a job is due, with no cron trigger to set up.
Before you start
- A Cloudflare account, and Wrangler signed in:
npx wrangler login. - R2 enabled in the Cloudflare dashboard. Without it, the first deploy fails with
inherit binding 'MEDIA' is invalid.
The quickest start is npm create tenoncms@latest with Astro and the target Cloudflare. It writes every file below. The Worker is named after the project folder, and its bucket <name>-media, so two sites on one account stay apart.
Set it up
To add Tenon to an Astro site on Cloudflare yourself:
Install the packages
npm install tenoncms @astrojs/cloudflare
npm install -D wrangler
pnpm add tenoncms @astrojs/cloudflare
pnpm add -D wrangler
yarn add tenoncms @astrojs/cloudflare
yarn add -D wrangler
bun add tenoncms @astrojs/cloudflare
bun add -D wrangler
Configure Astro
Use the Cloudflare adapter, and render pages on the server:
import cloudflare from "@astrojs/cloudflare";
import { defineConfig, envField } from "astro/config";
import tenonCms from "tenoncms/astro";
export default defineConfig({
output: "server",
adapter: cloudflare(),
// Tenon keeps its own sessions. Astro's sessions would need a KV namespace.
session: false,
integrations: [tenonCms()],
env: {
schema: {
TENON_SECRET: envField.string({ context: "server", access: "secret", min: 32 }),
TENON_SITE_URL: envField.string({
context: "server",
access: "secret",
url: true,
optional: true,
}),
},
},
});
The integration detects the adapter and runs the CMS in the object.
Add the CMS object
durableObject() is the database. The Worker entry exports the object class, and wrangler.jsonc binds it as CMS:
import { TENON_SECRET, TENON_SITE_URL } from "astro:env/server";
import { env } from "cloudflare:workers";
import { defineCms } from "tenoncms";
import { durableObject } from "tenoncms/cloudflare";
import { cloudflare } from "tenoncms/media/cloudflare";
import { r2 } from "tenoncms/media/r2";
export default defineCms({
database: durableObject(),
secret: TENON_SECRET,
site: { url: TENON_SITE_URL },
media: {
storage: r2(env.MEDIA),
images: { provider: cloudflare({ binding: env.IMAGES }) },
},
// Your collections…
});
import { handle } from "@astrojs/cloudflare/handler";
import { tenonObject } from "tenoncms/cloudflare";
import cms from "../tenon.config";
export const CmsObject = tenonObject(cms);
export default { fetch: handle } satisfies ExportedHandler<Env>;
{
"name": "my-site",
"main": "./src/worker.ts",
"compatibility_date": "2026-10-20",
"compatibility_flags": ["nodejs_compat"],
"durable_objects": {
"bindings": [{ "name": "CMS", "class_name": "CmsObject" }],
},
"migrations": [{ "tag": "v1", "new_sqlite_classes": ["CmsObject"] }],
// `wrangler deploy` creates the bucket when it is missing.
"r2_buckets": [{ "binding": "MEDIA", "bucket_name": "my-site-media" }],
"images": { "binding": "IMAGES" },
}
- The binding MUST be named
CMS. All content lives in one object. - Run
npx wrangler typesafter a change towrangler.jsonc. It writes theEnvtype of the bindings.
Set the secret for development
Put the secret in .dev.vars, which Wrangler reads in development. Keep the file out of git:
TENON_SECRET=<the output of openssl rand -hex 32>
Start the site
Run npm run dev, open /admin and create the first admin. Development simulates the object, the bucket and the Images binding.
Read content
Astro.locals.tenon is the client over the object, not the local API. It sends the request's cookie to the object, so the signed-in user's access rules apply, and the preview cookie shows drafts:
| On other targets | On Cloudflare |
|---|---|
withDrafts() and withSession() | None. The cookies decide |
create(…, { draft: true }) | createDraft() |
cms.localization | await localization() |
cms.email and cms.auth() | None |
| Any write from server code | Writes need a session or an API key |
See Differences to the local API for the rest.
output: "server".Media and images
r2(env.MEDIA)stores files through the bucket binding. It needs no keys and no CORS. Upload parts go through the Worker and the object.cloudflare({ binding: env.IMAGES })resizes images with Cloudflare Images.- An image service, like imgix, works too.
env comes from cloudflare:workers. See Media storage and Image providers.
Cloudflare Email Service sends through a send_email binding, with no SMTP server:
import { env } from "cloudflare:workers";
import { cloudflareEmail } from "tenoncms/email/cloudflare";
export default defineCms({
// ...
email: {
adapter: cloudflareEmail(env.EMAIL),
from: "My Site <hello@example.com>",
},
});
"send_email": [{ "name": "EMAIL" }],
- The sender's domain MUST be onboarded to Email Service in the Cloudflare dashboard.
wrangler devonly logs each mail. Add"remote": trueto the binding to send real mail in development.smtp()works on Workers too, on port 465 or 587.
See Cloudflare Email Service for its limits and errors.
tenon users recover needs the database itself, so it cannot reach a Durable Object. Email is then the way back in after a lost password.Deploy
- Set the secrets of the Worker:
npx wrangler secret put TENON_SECRET npx wrangler secret put TENON_SITE_URLTENON_SITE_URLis the public origin, likehttps://example.com. Add the other variables of your config the same way, likeEMAIL_FROM. - Build and deploy:
npm run deploy
The starter'sdeployscript runsastro build && wrangler deploy.wrangler deploycreates the bucket ofr2_bucketswhen it is missing. - Open
/adminon the deployed site and create the first admin.
The tenon CLI cannot load a Cloudflare config on your machine. Talk to the deployed site with --url:
npx tenon login --url https://example.com
npx tenon backup --url https://example.com
See Local or remote for which commands work that way.
Related resources
- Deployment overview: what every deployment needs, and a checklist.
- Astro: the integration and its options.
- Cloudflare Email Service: the binding and the API mode.
- The clock: how the object runs jobs.
- tenon login: sign in to the deployed site from the CLI.