Cloudflare Workers
Deploy Rivet Actors to Cloudflare Workers with Durable Objects for global edge computing with persistent state.
Feature Support
Feature | Supported |
---|---|
Horizontal scaling | Yes |
WebSockets | Yes |
SSE | Yes |
Edge | Yes |
Scheduling | Yes |
Setup
Install packages
Install the Cloudflare Workers driver:
Configure the driver
Update your server code to support Cloudflare Workers:
Configure Wrangler
Update your wrangler.json
configuration to support ACTOR_DO
and ACTOR_KV
bindings:
Configuration Requirements:
ACTOR_DO
- Durable Object binding for actor persistenceACTOR_KV
- KV namespace binding for metadata storagenodejs_compat
- Required compatibility flag- Migration with
ActorHandler
class definition
Deploy
Deploy your application to Cloudflare Workers:
Your actors will now run on Cloudflare's global edge network with persistent state backed by Durable Objects.
Examples
Cloudflare Workers + Hono
Example using Cloudflare Workers with Hono web framework.
Cloudflare Workers Basic
Basic Cloudflare Workers setup and configuration example.
Advanced
Accessing Environment Bindings
You can access Cloudflare Workers environment bindings directly using the importable env
:
Driver Context
The Cloudflare Workers driver provides access to the Durable Object state and environment through the driver context in createVars
.
The Cloudflare Workers driver context type is exported as DriverContext
from @rivetkit/cloudflare-workers
:
While you have access to the Durable Object state, be cautious when directly modifying KV storage or alarms, as this may interfere with RivetKit's internal operations and potentially break actor functionality.