Skip to main content

Function: routeDORequest()

routeDORequest(request, env, options): Promise<undefined | Response>

Defined in: packages/utils/src/route-do-request.ts:189

Routes requests to Durable Objects with support for authentication hooks and prefix matching.

A near drop-in replacement for Cloudflare's routeAgentRequest and PartyKit's routePartyRequest, with enhanced binding name matching flexibility and standard Cloudflare naming conventions.

URL Format: [/${prefix}]/${doBindingName}/${doInstanceNameOrId}[/path...]

Key Features:

  • Case-insensitive DO binding name matching (MY_DO matches my-do, MyDO, MyDo, etc.)
  • Supports both named instances and unique ID strings
  • Automatically detects 64-character hex strings and routes using idFromString()
  • Returns undefined if the request doesn't match (Hono convention)
  • Pre-request/connect hooks for authentication and Request enhancement
  • Comprehensive CORS support

Hook Behavior:

  • WebSocket requests (Upgrade: websocket) → calls onBeforeConnect only
  • Non-WebSocket requests → calls onBeforeRequest only

For complete documentation with examples, see https://lumenize.com/docs/utils/route-do-request

Parameters

request

Request

The incoming HTTP request to route

env

any

Environment object containing DO bindings

options

RouteOptions = {}

Configuration options for routing and hooks

Returns

Promise<undefined | Response>

Promise resolving to Response if request was handled, undefined if not matched

Throws

When binding name is found but doInstanceNameOrId is missing

Throws

When multiple DO bindings match the doBindingName segment