跳转到内容
简体中文

HonoBackend

此内容尚不支持你的语言。

Defined in: src/http/backend/HonoBackend.ts:132

Hono-backed HTTP backend — a thin adapter that compiles the actor-ts routing DSL onto a Hono app and serves it with Bun.serve. Hono is a lightweight router that runs well on Bun and covers the middleware cases we usually reach for (CORS, auth, logger) without pulling in Express.

hono is an optional peer dependency: install it only if you use this backend. Without a user-supplied app, the backend imports hono dynamically on listen().

new HonoBackend(options?): HonoBackend

Defined in: src/http/backend/HonoBackend.ts:148

HonoBackendOptions = {}

HonoBackend

readonly name: "hono" = 'hono'

Defined in: src/http/backend/HonoBackend.ts:133

HttpServerBackend.name

getApp(): HonoAppLike

Defined in: src/http/backend/HonoBackend.ts:157

Inject / access the underlying Hono app — useful for native middleware.

HonoAppLike


listen(host, port): Promise<ServerBinding>

Defined in: src/http/backend/HonoBackend.ts:185

Start listening. Returns a ServerBinding with the actual bound port.

string

number

Promise<ServerBinding>

HttpServerBackend.listen


registerRoute(route): void

Defined in: src/http/backend/HonoBackend.ts:162

Register all routes before listen is called. Duplicate paths must be rejected.

RouteRegistration

void

HttpServerBackend.registerRoute


registerWebSocket(reg): void

Defined in: src/http/backend/HonoBackend.ts:166

Optional capability: register a WebSocket endpoint. Backends that implement this support websocket() routes; absence is detected by HttpExtension.bind and reported as a clear error.

WebsocketRouteRegistration

void

HttpServerBackend.registerWebSocket


setDefaultResponseHeaders(headers): void

Defined in: src/http/backend/HonoBackend.ts:181

Optional: replace the header map the backend writes ahead of every response it emits — including the error, not-found and upgrade-reject responses no middleware ever sees. A response’s own header must still win, so these are written first and overwritten, not merged over.

HttpExtension wires withSecurityHeaders(...) here and passes {} for the opt-out. It is only called when that was configured: a backend comes with its own default (DEFAULT_RESPONSE_SECURITY_HEADERS for the shipped ones), so an untouched builder must not overwrite it.

Readonly<Record<string, string>>

void

HttpServerBackend.setDefaultResponseHeaders


setErrorHandler(handler): void

Defined in: src/http/backend/HonoBackend.ts:177

Optional: register a last-resort error handler. It MUST see both errors thrown by route handlers AND backend-internal errors (body parsing, etc.); if it throws, the backend falls back to its default error mapping. HttpExtension wires withErrorHandler here.

(err, request) => HttpResponse | Promise<HttpResponse>

void

HttpServerBackend.setErrorHandler


setNotFound(handler): void

Defined in: src/http/backend/HonoBackend.ts:173

Optional: register a method-agnostic not-found handler, invoked for any request that matched no route (including unmatched OPTIONS/HEAD). HttpExtension wires fallback() here. If the handler throws, the backend applies its default error mapping.

(request) => HttpResponse | Promise<HttpResponse>

void

HttpServerBackend.setNotFound