Overview
FlareDurableObject subclasses with per-DO HTTP and WebSocket arcs and per-instance containers on Cloudflare.
Durable Objects give you a single-threaded, addressable instance with durable storage and optional WebSocket hibernation. Flare models a Durable Object as a registered class: host.durableObject(Class) returns a handle carrying per-DO .http and .ws arcs, plus .mount(path) and .resolve(...), for that class.
Register a DO class
Section titled “Register a DO class”import { FlareHost, FlareResponse } from "@flare-ts/core";import { cf, FlareDurableObject } from "@flare-ts/core/cloudflare";
class ChatRoom extends FlareDurableObject { public static override deps = [];}
const host = new FlareHost(cf);const room = host.durableObject(ChatRoom);
room.http.get("/ping", () => new FlareResponse(200, { ok: true }));
room.ws.route("/stream").message((ws, scope) => { ws.send(scope.input.message.raw);});
room.mount("/rooms/:name");
const app = host.build();export default app.export();Each instance composes its own DI container seeded with DurableState and Bindings. User services registered with host.scoped() resolve lazily per instance.
Written against the platform directly, all of that lives inside the class: a raw Durable Object receives every request through one fetch(request), so routing is a hand-written branch on the URL, a WebSocket upgrade is a manual WebSocketPair, and whatever the instance needs is threaded through its constructor. Nothing ties the Worker side to the DO side; the paths the front door forwards and the paths the class switches on agree by convention, and a drifted path is a 404 served from inside your own object. Registration replaces that with the same declared surfaces the front door has: typed routes on the handle, a mount whose subtree conflicts fail build(), and per-instance wiring from the composed container.
Per-DO arcs vs Worker front door
Section titled “Per-DO arcs vs Worker front door”| Surface | Scope | Channels |
|---|---|---|
host.http / host.ws | Worker isolate (stateless) | WS channels not available |
room.http / room.ws | One DO instance | Full broadcast + hibernation |
Mount connects the Worker URL space to the DO namespace. Upgrades and HTTP calls on the mounted path reach the resolved instance; with a param-trailing mount like /rooms/:name, the trailing parameter is the instance name.
WebSocket hibernation
Section titled “WebSocket hibernation”On DO WebSocket routes, hibernate defaults to true. The platform may evict the instance while sockets stay open; handlers re-run on events with ws.state restored from attachments. Set hibernate: false to keep resident sockets in memory on that route.
Export the DO class
Section titled “Export the DO class”Export the DO class as a named export from the same module as export default app.export(); Wrangler resolves class_name against the module’s exports. Pair registration with [[durable_objects.bindings]] and migrations in wrangler.toml. See Register and mount.
Related
Section titled “Related”- Register and mount:
.mount()rules - State crossing: HTTP state across the boundary
- Test DOs in-process:
composeDurableInstance - WebSockets: contracts and channels on DO routes