@avedon/adapter-cloudflare
v6.0.1
Published
Cloudflare Workers adapter for avedon. Emits a Wrangler-deployable `build/` directory: static assets + SSG HTML, SSR Worker entry, and `wrangler.jsonc`. Optional **KV-backed ISR** when any route sets `revalidate`.
Readme
@avedon/adapter-cloudflare
Cloudflare Workers adapter for avedon. Emits a Wrangler-deployable build/ directory: static assets + SSG HTML, SSR Worker entry, and wrangler.jsonc. Optional KV-backed ISR when any route sets revalidate.
Config
import { cloudflareAdapter } from '@avedon/adapter-cloudflare'
export default {
adapter: cloudflareAdapter({
out: 'build',
name: 'my-avedon-app',
// isrKvBinding: 'AVEDON_ISR', // default
}),
}Build and deploy
pnpm build # avedon build → build/
cd build && wrangler deployRequires Wrangler 4+ and a Cloudflare account.
Sessions
Set the Worker secret:
wrangler secret put SESSION_SECRETIf server-entry exports session without secret, the generated Worker fills secret from env.SESSION_SECRET.
ISR (optional)
When any route has revalidate, adapt emits:
kv_namespaceswith bindingAVEDON_ISR(orisrKvBinding) and placeholder id<REPLACE_WITH_KV_NAMESPACE_ID>— replace with a real namespace id before deploy (wrangler kv namespace create …)assets.run_worker_firstfor ISR pathnames +POST /__avedon/revalidateso the Worker can intercept SSG HTML before Assets- Worker SWR: KV keys
html:{path},meta:{path},tags:{tag}; seed fromASSETS; background regen viactx.waitUntil+renderSsgPage - SSG GET fallback: if ISR miss, Worker still serves matching
render: 'ssg'HTML fromASSETSbeforecreateHandler
On-demand:
curl -X POST https://your-worker/__avedon/revalidate \
-H 'content-type: application/json' \
-d '{"path":"/stats"}'
# or {"tag":"stats"}Helpers revalidatePath / revalidateTag are also exported for custom handlers (pass { kv: env.AVEDON_ISR, routes, appHtml, assets: env.ASSETS }).
Without revalidate routes, behavior stays asset-first with no KV binding.
Dogfood (2026-08-09)
Live Worker avedon-isr-dogfood on account e3714019… with KV avedon-isr-dogfood (6ac88486…):
avedon buildwithcloudflareAdapter({ name: 'avedon-isr-dogfood' })- Replace placeholder KV id in
build/wrangler.jsonc wrangler deploy --config /abs/path/to/build/wrangler.jsonc(pass an absolute--config;pnpm exec wranglerfrom a nested cwd can resolve the wrong path)- Verified:
GET /isr-lab/serves SSG HTML;POST /__avedon/revalidatewith{"tag":"isr-lab"}regenerates (builtAtadvances)
Notes
- Targets Workers + Assets, not Pages Functions.
- Paths never built at
avedon buildare not created on revalidate (same as Node/Bun).
