Base class for Cloudflare Durable Objects with built-in routing support.
This package provides a convenient base class that extends Cloudflare's DurableObject with automatic routing capabilities using @whi/cf-routing.
import { BaseDurableObject } from '@whi/cf-do-base';import { DurableObjectRouteHandler, DurableObjectContext } from '@whi/cf-routing';class CounterHandler extends DurableObjectRouteHandler { async get(ctx: DurableObjectContext) { const count = await this.storage.get('count') || 0; return { count }; }}export class Counter extends BaseDurableObject { constructor(state, env) { super(state, env, 'counter'); this.router.defineRouteHandler('/count', CounterHandler); }} Copy
import { BaseDurableObject } from '@whi/cf-do-base';import { DurableObjectRouteHandler, DurableObjectContext } from '@whi/cf-routing';class CounterHandler extends DurableObjectRouteHandler { async get(ctx: DurableObjectContext) { const count = await this.storage.get('count') || 0; return { count }; }}export class Counter extends BaseDurableObject { constructor(state, env) { super(state, env, 'counter'); this.router.defineRouteHandler('/count', CounterHandler); }}
Base class for Cloudflare Durable Objects with built-in routing support.
This package provides a convenient base class that extends Cloudflare's DurableObject with automatic routing capabilities using @whi/cf-routing.
Example