@plumix/runtime-cloudflare
v0.1.0
Published
Cloudflare Workers runtime adapter for Plumix
Downloads
167
Maintainers
Readme
@plumix/runtime-cloudflare
The Cloudflare Workers runtime for Plumix — the adapters that wire your site to D1, R2, KV, Images, and the edge cache. It's the first of Plumix's pluggable runtimes; the CMS itself is runtime-agnostic, so this package is swappable.
Install
pnpm add @plumix/runtime-cloudflareYour worker needs Node compatibility. In wrangler.jsonc:
{
"compatibility_flags": ["nodejs_compat"],
}Usage
Each adapter is a small factory you slot into the matching field of your plumix.config.ts:
import { auth, plumix } from "plumix";
import {
cloudflare,
cloudflareDeployOrigin,
d1,
images,
r2,
} from "@plumix/runtime-cloudflare";
const { rpId, origin } = cloudflareDeployOrigin({
workerName: "my-site",
accountSubdomain: "my-account",
localOrigin: "http://localhost:5173",
});
export default plumix({
runtime: cloudflare(),
database: d1({ binding: "DB", session: "auto" }),
storage: r2({ binding: "MEDIA", publicUrlBase: "https://media.example.com" }),
imageDelivery: images({ zone: "media.example.com" }),
auth: auth({ passkey: { rpName: "My Site", rpId, origin } }),
});Adapters
| Factory | Field | What it does |
| ------------------------------------- | --------------- | ---------------------------------------------------------------------------------------------------- |
| cloudflare() | runtime | Bridges the Workers environment to Plumix. |
| d1({ binding, session }) | database | D1 (SQLite). session is "disabled" | "auto" | "primary-first" for read replication. |
| r2({ binding, publicUrlBase, s3 }) | storage | R2 object storage. Add s3 credentials to enable presigned-PUT uploads. |
| images({ zone }) | imageDelivery | Cloudflare Image Transformations URLs. zone is a hostname, no protocol. |
| edge({ ttl, staleWhileRevalidate }) | cache | Edge cache (Cache API + purge-by-tag). |
| kv({ binding }) | kv | Cloudflare KV. |
| cloudflareDeployOrigin({ … }) | — | Derives rpId + origin from the Workers Builds env, with a localOrigin fallback for pnpm dev. |
Each binding matches a resource declared in your wrangler.jsonc (d1_databases, r2_buckets, kv_namespaces).
Notes
cloudflareDeployOriginresolves the passkey relying-party origin per deploy: production →<worker>.<account>.workers.dev, preview →<branch>-<worker>.<account>.workers.dev, local → yourlocalOrigin. Swap it for a hardcoded{ rpId, origin }once you're on a custom domain.edge()is dormant until you attach a zone. It readsCF_ZONE_ID+CF_CACHE_PURGE_TOKENfrom the worker env and renders live (no caching) when either is missing — so it's a safe no-op on*.workers.dev.- Presigned R2 uploads need bucket CORS rules and S3 credentials; see
@plumix/plugin-mediafor the details.
Support
Have a question? Start a discussion. Found a bug? Open an issue.
Contributing
PRs and ideas welcome. The Contributing guide gets you set up — new contributors especially welcome.
License
MIT © Plumix Contributors
