Skip to content

Resources

wrangler d1 create my-site                         # copy the database_id into wrangler.jsonc
wrangler r2 bucket create my-site-media

wrangler.jsonc (the binding names are fixed):

{
  "main": "./src/worker.ts",
  "compatibility_flags": ["nodejs_compat", "global_fetch_strictly_public"],
  "assets": { "binding": "ASSETS", "directory": "./dist" },
  "triggers": { "crons": ["* * * * *"] },          // jobs, schedules and scheduled publishing
  "d1_databases": [{ "binding": "CMS_DB", "database_name": "my-site", "database_id": "<id>", "migrations_dir": "node_modules/@kevolution-co/cms/migrations" }],
  "r2_buckets": [{ "binding": "CMS_MEDIA", "bucket_name": "my-site-media" }],
  "images": { "binding": "IMAGES" },               // image variants, cropping and formats
  "send_email": [{ "name": "EMAIL" }],             // invitations, password reset, email confirmation
  // live presence in the panel (who has each document open); optional: the panel works the same without it
  "durable_objects": { "bindings": [{ "name": "CMS_PRESENCE", "class_name": "CmsPresence" }] },
  "migrations": [{ "tag": "v1", "new_sqlite_classes": ["CmsPresence"] }],
  "vars": { "CMS_URL": "https://my-site.com", "CMS_EMAIL_FROM": "no-reply@my-site.com" }
}

src/worker.ts exports Astro's request handler and the CMS cron:

import astro from "@astrojs/cloudflare/entrypoints/server";
import { scheduled } from "@kevolution-co/cms/worker";
export { CmsPresence } from "@kevolution-co/cms/worker"; // live presence (with the binding above)
export default { ...astro, scheduled };