Hono backend
Это содержимое пока не доступно на вашем языке.
Hono is a runtime-agnostic HTTP
framework — the same code runs on Bun, Node, Deno, Cloudflare
Workers, AWS Lambda, Vercel, etc. HonoBackend wraps it for
actor-ts.
import { ActorSystem } from 'actor-ts';import { HttpExtensionId } from 'actor-ts/http';import { HonoBackend, HonoBackendOptions } from 'actor-ts/http';
const http = system.extension(HttpExtensionId);
await http.newServerAt('0.0.0.0', 8080) .useBackend(new HonoBackend()) .bind(routes);When to use Hono
Section titled “When to use Hono”Hono is the right pick when:
- Edge / serverless — Cloudflare Workers, Vercel Edge, Deno Deploy. Hono is one of the few HTTP frameworks that works in those environments.
- Cross-runtime portability — same code on Bun + Node + Edge.
- Minimal overhead — Hono is lighter than Fastify, faster than Express.
For a typical long-running production server, Fastify is usually preferable — bigger plugin ecosystem, more production hours. Hono shines when “runs in many places” is a hard requirement.
Cross-runtime + serverless caveat
Section titled “Cross-runtime + serverless caveat”// On a long-running VM: this worksawait http.newServerAt('0.0.0.0', 8080) .useBackend(new HonoBackend()) .bind(routes);
// On Cloudflare Workers: there's no "newServerAt(host, port)"// The runtime invokes a handler per request.HonoBackend exposes its underlying Hono instance:
const backend = new HonoBackend();const honoApp = backend.getApp(); // ← export to the edge runtimeIn Cloudflare Workers:
export default { fetch: honoApp.fetch };The framework’s actor-ts side then runs in-memory inside the isolate — short-lived, no clustering, no persistence. Useful for stateless request-handling logic that benefits from actor patterns (state machines, validation pipelines).
For long-running actor systems with cluster + persistence, don’t run on edge runtimes — they’re isolate-per-request, not long-lived processes.
Configuration
Section titled “Configuration”// Hono itself has minimal config; most settings come via routes / middleware.// The request-body cap defaults to 1 MiB, as on every backend; raise it// with HonoBackendOptions where an endpoint takes more:const honoBackendOptions = HonoBackendOptions.create().withMaxBodyBytes(4 * 1024 * 1024);new HonoBackend(honoBackendOptions);The server-wide actor-ts.http.server.max-content-length sets the same cap
without touching the backend, and it holds on every runtime this backend
runs on: the body is read by this backend’s own code, so Bun and Deno count it
exactly as Node does — a declared length over it is refused before a byte is
read, a chunked body is abandoned once it crosses it. A backend built with a
different withMaxBodyBytes is refused at bind(), naming both.
Security headers
Section titled “Security headers”Every response this backend writes carries
X-Content-Type-Options: nosniff — its error mapping, the fallback 404
and the body-too-large 413 included, none of which a middleware sees.
A response’s own header still wins.
Configure it per server, not per backend — one surface instead of three:
await http.newServerAt('0.0.0.0', 8080) .useBackend(new HonoBackend()) .withSecurityHeaders(false) // or a SecurityHeadersOptions bundle .bind(routes);Hono middleware
Section titled “Hono middleware”import { logger, cors, secureHeaders } from 'hono/middleware';
const backend = new HonoBackend();await http.newServerAt('0.0.0.0', 8080) .useBackend(backend) .bind(routes);
backend.getApp().use('*', logger());backend.getApp().use('/api/*', cors());backend.getApp().use('*', secureHeaders());Hono’s middleware ecosystem is smaller than Express’s but
covers the common cases — CORS, security headers, JWT auth,
basic auth, compression. For JWT verification that behaves the
same on every backend, use the portable
JwtAuth instead of Hono’s own.
Peer dependency
Section titled “Peer dependency”npm install hono# or: bun add honoPerformance
Section titled “Performance”Rough numbers:
- 100K-150K req/sec on Bun for trivial routes.
- Slightly slower than Fastify on Node.
- Edge runtime numbers depend on the platform (Cloudflare Workers: ~50K req/sec per worker; throttled by the platform).
Edge runtime caveats
Section titled “Edge runtime caveats”WebSockets and abort()
Section titled “WebSockets and abort()”websocket() routes work on every runtime this backend runs on, through
Hono’s own adapter for each. What a connection’s abort() — and a server
shutdown that cuts its sockets — does depends on the socket that adapter hands
over. On Bun (Bun.serve’s ServerWebSocket) and on Node
(@hono/node-ws, which hands over a ws socket) the socket has a hard close,
so abort() drops the connection on the spot: the client sees it close with
1006 and no close frame, as on the Fastify and Express backends. On Deno
the socket is a standard WebSocket, which has no hard close, so abort()
falls back to a close frame carrying its code and reason. Measured on bun 1.4.2,
bun 1.4.4, node v26.10.0 and deno 2.6.8.
TLS and HTTP/2
Section titled “TLS and HTTP/2”Set on the server options like every backend (see TLS and HTTP/2); Hono hands the pair to whichever runtime it is on:
| Runtime | TLS | http2: true |
|---|---|---|
| Bun | Bun.serve({ tls }) | Bun.serve({ http2: true }) — h2 through ALPN, HTTP/1.1 kept; Bun ≥ 1.4.1, refused on an older one |
| Node | https.createServer under @hono/node-server | http2.createSecureServer with allowHTTP1 |
| Deno | Deno.serve({ cert, key }) | negotiated whenever TLS is on; no knob, so the flag records intent |
Client-certificate verification (requestClientCert) reaches the Bun and
Node sockets; Deno.serve has no client-auth option, so on Deno it is
refused at bind rather than accepted and not applied. It needs a ca to
verify against: without one, bind refuses it on every runtime, because the
TLS stack would otherwise check client certificates against the runtime’s
default trust store and admit any certificate a public CA issued.
Where to next
Section titled “Where to next”- HTTP overview — the bigger picture.
- Fastify backend — for Node / Bun production servers.
- Express backend — for Express-middleware-rich apps.
- Hono docs — Hono’s own documentation.
