Environment type extending base Env interface
Create a new BaseDurableObject instance
Durable Object state provided by Cloudflare
Environment bindings containing KV namespaces, secrets, etc.
Optionalname: stringOptional name for the router (used in logging). Defaults to 'unnamed'
Optionalrouter_args: [RouterOptions<unknown, any[]>?]Optional arguments passed to the underlying itty-router instance
ProtectedrouterThe DurableObjectRouter instance handling all requests
Protected OptionalnameOptional name for the router (used in logging). Defaults to 'unnamed'
Handle incoming requests
This method is called by Cloudflare for each HTTP request to the Durable Object. It delegates all request handling to the router.
The incoming HTTP request
A Promise resolving to the HTTP response
The fetch method is automatically called by Cloudflare Workers. You typically don't need to override this unless you need custom request preprocessing:
async fetch(request: Request): Promise<Response> {
// Custom preprocessing
console.log('Received request:', request.url);
// Delegate to router
return super.fetch(request);
}
Base class for Durable Objects with built-in routing capabilities
This class extends Cloudflare's DurableObject and automatically initializes a DurableObjectRouter instance. Subclasses can define routes in their constructor using the
this.routerproperty.Example
Basic usage with route handlers
Example
With custom router configuration