Skip to content

Cloudflare Adapter

The Cloudflare adapter is the default runtime for CruzJS, providing edge-deployed applications with D1, KV, R2, Queues, and Workers AI.

Terminal window
npm install @cruzjs/adapter-cloudflare
server.cloudflare.ts
import { CloudflareAdapter } from '@cruzjs/adapter-cloudflare';
export default createCruzApp({
schema,
modules: [/* your modules */],
adapter: new CloudflareAdapter(),
pages: () => import('virtual:react-router/server-build'),
});
new CloudflareAdapter({
kvBindingName: 'CACHE_KV', // Override KV binding name
r2BindingName: 'UPLOADS_BUCKET', // Override R2 binding name
});
CruzJS BindingCloudflare ServiceBinding Name
DatabaseD1DB
CacheKVCACHE_KV
StorageR2UPLOADS_BUCKET
QueueQueuesDynamic (by name)
AIWorkers AI + AI GatewayAI

In local development (without wrangler), the adapter automatically provides:

  • In-memory KV for caching
  • In-memory queues with consumer registration
  • SQLite fallback for D1 via better-sqlite3

edge — Runs in V8 isolates at Cloudflare’s edge network. Sub-millisecond cold starts.