Bun HTTP adapter implementation.
-
close(handle: ServerHandle): Promise<void>
Stops the server gracefully.
-
fetch(request: Request): Response | Promise<Response>
The universal web-standard entry point. Accepts a web
Requestand returns a webResponse. May be called withoutlisten(e.g. Cloudflare Workers whereexport default { fetch: app.fetch }is the deploy path). -
listen(): Promise<ServerHandle>port: number,hostname?: string
Binds the adapter's
fetchto a real TCP socket. -
setHandler(handler: (request: IRequest) => IResponse | Promise<IResponse>): void
Installs the framework request handler. Called once at
start()time, after the middleware pipeline compiles and before anyfetchorlisten. -
setRpcHandler(handler: RpcFetchHandler): void
Installs a gRPC/Connect fetch handler.
-
setUpgradeRouter(router: WebSocketUpgradeRouter): void
Installs a WebSocket upgrade router. The adapter stores the router but does not consult it: since M70a the kernel's terminal handler resolves
IWebSocketServiceand callsrouteUpgradeitself, after the middleware pipeline has run without short-circuiting and before route matching — so an application catch-all cannot shadow an upgrade. What the adapter needs from this setter is the bare fact that a router was installed: Node attaches its rawupgradelistener only then.
Cloudflare Workers HTTP adapter implementation.
-
close(_handle: ServerHandle): Promise<void>
Stops the server gracefully.
-
fetch(request: Request): Response | Promise<Response>
The universal web-standard entry point. Accepts a web
Requestand returns a webResponse. May be called withoutlisten(e.g. Cloudflare Workers whereexport default { fetch: app.fetch }is the deploy path). -
listen(): Promise<ServerHandle>_port: number,_hostname?: string
Binds the adapter's
fetchto a real TCP socket. -
setHandler(handler: (request: IRequest) => IResponse | Promise<IResponse>): void
Installs the framework request handler. Called once at
start()time, after the middleware pipeline compiles and before anyfetchorlisten. -
setRpcHandler(handler: RpcFetchHandler): void
Installs a gRPC/Connect fetch handler.
-
setUpgradeRouter(router: WebSocketUpgradeRouter): void
Installs a WebSocket upgrade router. The adapter stores the router but does not consult it: since M70a the kernel's terminal handler resolves
IWebSocketServiceand callsrouteUpgradeitself, after the middleware pipeline has run without short-circuiting and before route matching — so an application catch-all cannot shadow an upgrade. What the adapter needs from this setter is the bare fact that a router was installed: Node attaches its rawupgradelistener only then.
Deno HTTP adapter implementation.
-
close(handle: ServerHandle): Promise<void>
Stops the server gracefully.
-
fetch(request: Request): Response | Promise<Response>
The universal web-standard entry point. Accepts a web
Requestand returns a webResponse. May be called withoutlisten(e.g. Cloudflare Workers whereexport default { fetch: app.fetch }is the deploy path). -
listen(): Promise<ServerHandle>port: number,hostname?: string
Binds the adapter's
fetchto a real TCP socket. -
setHandler(handler: (request: IRequest) => IResponse | Promise<IResponse>): void
Installs the framework request handler. Called once at
start()time, after the middleware pipeline compiles and before anyfetchorlisten. -
setRpcHandler(handler: RpcFetchHandler): void
Installs a gRPC/Connect fetch handler.
-
setUpgradeRouter(router: WebSocketUpgradeRouter): void
Installs a WebSocket upgrade router. The adapter stores the router but does not consult it: since M70a the kernel's terminal handler resolves
IWebSocketServiceand callsrouteUpgradeitself, after the middleware pipeline has run without short-circuiting and before route matching — so an application catch-all cannot shadow an upgrade. What the adapter needs from this setter is the bare fact that a router was installed: Node attaches its rawupgradelistener only then.
Node HTTP adapter implementation.
-
close(handle: ServerHandle): Promise<void>
Stops the server gracefully.
-
fetch(request: Request): Response | Promise<Response>
The universal web-standard entry point. Accepts a web
Requestand returns a webResponse. May be called withoutlisten(e.g. Cloudflare Workers whereexport default { fetch: app.fetch }is the deploy path). -
listen(): Promise<ServerHandle>port: number,hostname?: string
Binds the adapter's
fetchto a real TCP socket. -
setHandler(handler: (request: IRequest) => IResponse | Promise<IResponse>): void
Installs the framework request handler. Called once at
start()time, after the middleware pipeline compiles and before anyfetchorlisten. -
setRpcHandler(handler: RpcFetchHandler): void
Installs a gRPC/Connect fetch handler.
-
setUpgradeRouter(router: WebSocketUpgradeRouter): void
Installs a WebSocket upgrade router. The adapter stores the router but does not consult it: since M70a the kernel's terminal handler resolves
IWebSocketServiceand callsrouteUpgradeitself, after the middleware pipeline has run without short-circuiting and before route matching — so an application catch-all cannot shadow an upgrade. What the adapter needs from this setter is the bare fact that a router was installed: Node attaches its rawupgradelistener only then.
Owns the ws server for one Node HTTP adapter and performs the handshake.
-
close(): void
Shuts down the
wsserver, when one was ever created. -
handshake(): Promise<void>incoming: NodeIncomingMessage,socket: unknown,head: unknown,sink: WebSocketEventSink,protocol?: string
Completes the RFC 6455 handshake over an already-accepted TCP connection and binds the resulting socket to the decision's sink.
-
hasServer(): boolean
Whether a
wsserver has been created yet.
Raised when a request body exceeds the configured
RuntimeOptions.maxBodyBytes cap.
-
maxBodyBytes: number
The configured cap, in bytes.
Stores an adapter's RPC interceptor and consults it safely.
-
consult(request: Request): Promise<Response | null>
Calls the installed handler. Returns the handler's response if it returns a
Response, otherwise returnsnull. -
set(handler: RpcFetchHandler): void
Installs the handler. A later call replaces the previous one.
Narrows an already-imported module to WsModuleLike.
Probes a server handle for the raw upgrade event.
Binds a Workers server socket's events to a sink.
Binds a Deno socket's event handlers to a sink.
Binds a ws socket's events to a sink.
Builds the default BunHost from node: built-ins, which Bun
implements.
Builds the default NodeHost from node: built-ins, which Deno
and Bun also implement.
Creates IRuntimeServices backed by Bun APIs.
Builds the serve-time handler object that routes every Bun socket event to
the sink stored on that socket's data.
Creates IRuntimeServices for Cloudflare Workers.
Builds the default host from the real Workers globals.
Creates an IDnsResolver backed by Deno.resolveDns.
Creates IRuntimeServices backed by Deno APIs.
Creates an IDnsResolver backed by node:dns/promises.
Creates IRuntimeServices backed by Node.js APIs.
Creates an IWorkerHost backed by node:worker_threads.
Creates runtime services for the current platform.
Reconstructs a web-standard Request from Node's upgrade event arguments,
so the upgrade router sees the same shape on every runtime.
Wraps a web-API socket as an IWebSocketTransport.
Creates an IWorkerHost backed by the web-standard Worker API
(Deno and Bun).
Wraps a ws socket as an IWebSocketTransport.
Detects the current runtime platform.
Reports whether a set of request headers describes an RFC 6455 WebSocket upgrade.
Lazily imports ws and narrows it.
Normalizes an inbound frame payload to the framework's string | Uint8Array.
Refuses an upgrade on the raw socket, since there is no Response object to
return on Node's upgrade path.
Creates the RuntimePlugin that provides runtime-agnostic services and HTTP adapter.
Maps the web WebSocket API's numeric readyState to the framework's named
WebSocketReadyState.
Coerces an error-event payload into a real Error.
Maps a ws numeric ready state to the framework's named state.
File info returned by BunHost.stat().
Minimal interface covering the Bun-specific operations used by this adapter. Inject this interface to test the adapter without real Bun.
-
createReadStream: () => NodeJS.ReadableStream | nullpath: string,options?: { start?: number; end?: number; }
Create a read stream for a file. Returns null if the file cannot be opened.
-
env: { [key: string]: string | undefined; }
Environment variable map.
-
exit: (code?: number) => never
Exit the process.
-
hostname: string
Returns the host name.
-
mkdir: () => booleanpath: string,options?: { recursive?: boolean; }
Create a directory.
-
onSignal: () => voidsignal: RuntimeSignal,handler: () => void
Registers a process-termination signal listener.
-
readFile: (path: string) => Uint8Array | null
Read file as bytes.
-
readdir: (path: string) => readonly string[] | null
List directory entries.
-
realPath: (path: string) => string | null
Resolve a path to its canonical absolute form (null when it cannot be resolved).
-
rm: () => booleanpath: string,options?: { recursive?: boolean; }
Remove a file or directory.
-
stat: (path: string) => BunFileInfo | null
Get file/directory info.
-
version: string
Bun version string.
-
writeFile: () => voidpath: string,data: Uint8Array
Write bytes to a file.
The built-ins buildBunHost needs, injectable so every wrapper is
unit-testable without real file-system access. Shapes match node:fs (sync),
node:os, and node:process, all of which Bun implements.
-
bunGlobal: { version?: string; } | undefined
The
Bunglobal when running on Bun,undefinedelsewhere — read only for its version string. Required (rather than optional) so callers and tests state it explicitly and every version-resolution arm stays reachable. -
fs: { createReadStream?: () => NodeJS.ReadableStream | null; readFileSync(path: string): Uint8Array; realpathSync(path: string): string; writeFileSync(path: string,options?: { start?: number; end?: number; }): void; statSync(path: string): { size: number; mtime: Date; isFile(): boolean; isDirectory(): boolean; }; readdirSync(path: string): string[]; mkdirSync(path: string,data: Uint8Array): string | undefined; rmSync(path: string,options?: { recursive?: boolean; }): void; }path: string,options?: { recursive?: boolean; }
Synchronous file-system operations (compatible with
node:fs). -
hostname: () => string
Hostname function (from
node:os). -
proc: { version: string; versions: Record<string, string | undefined>; env: Record<string, string | undefined>; exit: (code?: number) => never; on: () => void; }event: RuntimeSignal,listener: () => void
Process object (version, env, exit, signal listening).
Minimal interface covering the Bun-specific HTTP operations used by this adapter. Inject this interface to test the adapter without real Bun.
Bun server handle (from Bun.serve).
-
stop(): void
Stops the server gracefully.
-
upgrade(): booleanrequest: Request,options: { data: BunSocketData; headers?: Headers; }
Upgrades an inbound request to a WebSocket.
A Bun ServerWebSocket, narrowed to what this adapter drives.
-
data: BunSocketData
The data bag supplied to
server.upgrade().
The per-socket data Bun carries from server.upgrade() through to every
socket handler.
-
sink: WebSocketEventSink
The sink this socket's events are routed to.
The serve-time socket handler object Bun expects under Bun.serve's
websocket option.
-
close(): voidws: BunServerWebSocket,code: number,reason: string
Called once on close.
-
error(): voidws: BunServerWebSocket,error: unknown
Called on transport error.
-
message(): voidws: BunServerWebSocket,message: string | Uint8Array
Called per inbound frame.
-
open(ws: BunServerWebSocket): void
Called once the socket is live.
Injectable environment seam for Cloudflare Workers bindings. Defaults to an empty record so the adapter is testable without Workers globals.
Options for createCloudflareRuntimeServices.
-
env: CloudflareEnv
Injectable env source for reading Workers bindings. Defaults to an empty record.
The server half of a Workers WebSocketPair. Workers sockets are driven with
addEventListener after an explicit accept(), not with on* properties.
-
accept(): void
Puts the server socket into the accepted state so it can send and receive.
-
addEventListener(): voidtype: string,listener: (event: never) => void
Subscribes to a socket event.
Injectable seam covering the two Workers-only globals this upgrader needs.
-
createPair(): CloudflareWebSocketPair
Creates a linked client/server socket pair.
-
createUpgradeResponse(): Responseclient: unknown,protocol?: string
Builds the 101 response that hands the client half back to the peer.
A created WebSocketPair: the client half travels back in the 101 response,
the server half stays here.
-
client: unknown
The half handed to the client in the response.
-
server: CloudflareServerSocket
The half the server keeps.
Options for createRuntimeServices.
-
adapters: RuntimeAdapterFactories
Replace the built-in platform → factory map.
-
env: Readonly<Record<string, unknown>>
The Cloudflare Workers
envrecord, which is the only way bindings and variables reach a Worker — there is no ambientprocess.envon the edge. -
platform: RuntimePlatform
Build services for this platform instead of auto-detecting.
The Deno.resolveDns surface this resolver needs.
-
resolveDns(): Promise<DenoSrvRecord[]>query: string,recordType: "SRV"
Resolves SRV records.
File info returned by DenoHost.stat().
Minimal interface covering the Deno-specific operations used by this adapter. Inject this interface to test the adapter without real Deno.
-
addSignalListener(): voidsignal: RuntimeSignal,handler: () => void
Registers a signal listener.
-
build: { os: string; }
Build metadata. Read for
osalone, to decide whether signal listening is available — seecreateDenoRuntimeServices. -
env: { toObject(): Record<string, string>; }
Environment variable map.
-
exit(code?: number): never
Exit the process.
-
hostname(): string
Returns the host name.
-
mkdir(): Promise<void>path: string,options?: { recursive?: boolean; }
Create a directory.
-
open(path: string): Promise<Deno.FsFile>
Open a file for reading.
-
readDir(path: string): AsyncIterable<DenoDirEntry>
Lists directory entries. Named and shaped after the real API this host defaults to:
Deno.readDir(capitalD) returns an async iterable, so it must be consumed withfor await. -
readFile(path: string): Promise<Uint8Array>
Read file as bytes.
-
realPath(path: string): Promise<string>
Resolve a path to its canonical absolute form, following symlinks.
-
remove(): Promise<void>path: string,options?: { recursive?: boolean; }
Remove a file or directory.
-
resolveDns(): Promise<DenoSrvRecord[]>query: string,recordType: "SRV"
Resolves SRV records.
-
stat(path: string): Promise<DenoFileInfo>
Get file/directory info.
-
version: { deno: string; }
Current runtime version string.
-
writeFile(): Promise<void>path: string,data: Uint8Array
Write bytes to a file.
Minimal interface covering the Deno operations this adapter needs. Inject this interface to test the adapter without real Deno.
-
serve(options: { port: number; hostname?: string; fetch: (request: Request) => Response | Promise<Response>; }): DenoServer
Starts an HTTP server.
-
upgradeWebSocket(): DenoWebSocketUpgraderequest: Request,options?: { protocol?: string; }
Performs an RFC 6455 handshake on an inbound request.
Deno HTTP server handle (from Deno.serve).
-
shutdown(): Promise<void>
Shuts down the server.
One SRV record as Deno.resolveDns returns it.
-
port: number
TCP port.
-
priority: number
RFC 2782 priority.
-
target: string
Target hostname.
-
weight: number
RFC 2782 weight.
A web-API socket that exposes the on* handler properties, as Deno's
upgradeWebSocket socket does.
-
onclose: ((event: { code: number; reason: string; }) => void) | null
Fires once on close.
-
onerror: ((event: unknown) => void) | null
Fires on transport error.
-
onmessage: ((event: { data: unknown; }) => void) | null
Fires per inbound frame.
-
onopen: ((event: unknown) => void) | null
Fires once the socket is writable.
The result shape of Deno.upgradeWebSocket.
-
response: Response
The 101 response that must be returned from the fetch handler.
-
socket: DenoWebSocketLike
The server-side socket.
Minimal global scope shape needed for detection.
Allows injecting a fake global for testing without as casts in test code.
Map of platform → HTTP adapter factory. Used internally for dependency injection.
Options every IHttpAdapter implementation in this package
accepts, supplied by RuntimePlugin when it constructs one.
-
maxBodyBytes: number
Maximum request-body size, in bytes, enforced where the body is actually read. Omitted, the read is unbounded — the released behaviour.
The node:dns/promises surface this resolver needs, injectable so every
branch is unit-testable without real DNS or network permission.
-
resolve4(hostname: string): Promise<string[]>
Resolves IPv4 addresses.
-
resolve6(hostname: string): Promise<string[]>
Resolves IPv6 addresses.
-
resolveSrv(hostname: string): Promise<>{ name: string; port: number; priority: number; weight: number; }[]
Resolves SRV records.
File info returned by NodeHost.stat().
Minimal interface covering the Node-specific operations used by this adapter. Inject this interface to test the adapter without real Node.js.
-
createReadStream: () => NodeJS.ReadableStream | nullpath: string,options?: { start?: number; end?: number; }
Create a read stream for a file. Returns null if the file cannot be opened.
-
env: Record<string, string | undefined>
Environment variable map.
-
exit: (code?: number) => never
Exit the process.
-
hostname: string
Host name string.
-
mkdir: () => Promise<void>path: string,options?: { recursive?: boolean; }
Create a directory.
-
nodeVersion: string
Node.js version string (e.g. "v18.19.0").
-
onSignal: () => voidsignal: RuntimeSignal,handler: () => void
Registers a process-termination signal listener.
-
readFile: (path: string) => Promise<Uint8Array>
Read file as bytes.
-
readdir: (path: string) => Promise<readonly string[]>
List directory entries.
-
realPath: (path: string) => Promise<string>
Resolve a path to its canonical absolute form, following symlinks.
-
rm: () => Promise<void>path: string,options?: { recursive?: boolean; }
Remove a file or directory.
-
stat: (path: string) => Promise<NodeFsInfo>
Get file/directory info.
-
writeFile: () => Promise<void>path: string,data: Uint8Array
Write bytes to a file.
A Node IncomingMessage, narrowed to what building an upgrade Request
needs.
-
headers: Record<string, string | string[] | undefined>
Raw headers, as Node's lowercase-keyed object.
-
method: string | undefined
The HTTP method.
-
url: string | undefined
The request target (path plus query), as Node reports it.
-
fs: NodeFsOperations
File-system operations (compatible with
node:fs/promises). -
hostname: () => string
Hostname function (from
node:os). -
proc: { version: string; env: Record<string, string | undefined>; exit: (code?: number) => never; on: () => void; }event: RuntimeSignal,listener: () => void
Process object (version, env, exit, signal listening).
Minimal interface covering the @hono/node-server serve() operation.
Inject this interface to test the adapter without a real Node server.
Node.js HTTP server handle (returned by @hono/node-server serve()).
-
close(): void
Stops the server gracefully.
Minimal shape of a node:worker_threads Worker as used by this host.
-
on(): unknownevent: "message" | "error" | "exit",listener: (arg: unknown) => void
Registers an event listener (
'message'payloads arrive unwrapped;'exit'receives the numeric exit code). -
postMessage(value: unknown): void
Posts a structured-clonable message to the worker.
-
terminate(): Promise<number>
Terminates the worker; resolves with the exit code.
The Node built-ins this host needs. Inject fakes to test without real threads.
-
Worker: new (specifier: string | URL) => NodeWorkerLike
The
worker_threads.Workerconstructor. -
availableParallelism: () => number
os.availableParallelism.
The raw socket handed to a Node upgrade listener, narrowed to what a
refusal needs.
-
destroy(): void
Closes the socket.
-
write(data: string): void
Writes bytes to the socket.
Map of platform → runtime adapter factory.
-
bun: () => IRuntimeServices
Factory for Bun.
-
cloudflare-workers: () => IRuntimeServices
Factory for Cloudflare Workers.
-
deno: () => IRuntimeServices
Factory for Deno.
-
node: () => IRuntimeServices
Factory for Node.js.
Options for RuntimePlugin.
-
adapters: RuntimeAdapterFactories
Override runtime adapter factories for testing. When provided, the plugin uses these instead of the real adapter factories, allowing unit tests to run without OS permissions or real runtime globals.
-
env: Readonly<Record<string, unknown>>
The Cloudflare Workers
envrecord. There is no ambient environment on the edge, so without thisruntime.envis empty on Workers andConfigPluginreads nothing. -
httpAdapters: HttpAdapterFactories
Override HTTP adapter factories for testing. When provided, the plugin uses these instead of the default HTTP adapters, allowing unit tests to inject fake HTTP adapters.
-
maxBodyBytes: number
Maximum request-body size, in bytes, enforced where the body is read. Omitted, the read is unbounded — the released behaviour, byte for byte.
-
platform: RuntimePlatform
Force a specific platform instead of auto-detecting. Useful for testing or when running in an environment where detection might be ambiguous.
An event emitter that can report raw HTTP upgrades — the one capability this
adapter needs from the node:http server that serve() returns.
-
on(): unknownevent: "upgrade",listener: (...args: never[]) => void
Subscribes to the raw
upgradeevent.
The subset of the web WebSocket API the runtime adapters drive. Declared
structurally so no module depends on a platform's global types and a fake
can stand in during unit tests.
-
close(): voidcode?: number,reason?: string
Closes the socket.
-
readyState: number
Numeric ready state, per the web WebSocket API.
-
send(data: string | Uint8Array): void
Sends a text or binary frame.
The web globals this host needs. Inject fakes to test without spawning real workers.
-
Worker: new () => WebWorkerLikespecifier: string,options: { type: "module"; }
The
Workerconstructor; absent on runtimes without web workers. -
hardwareConcurrency: number
Reported hardware concurrency (
navigator.hardwareConcurrency).
Host-construction options that vary between the runtimes sharing this implementation.
-
exitEventName: string
Name of the non-standard event this runtime emits when a worker's thread ends. Bun emits
'close'; Deno emits nothing at all, so it passes nothing and the handles this host produces omitonExitentirely.
Minimal shape of a web Worker instance as used by this host.
-
addEventListener(): voidtype: string,listener: (event: unknown) => void
Registers an event listener. Only used for the runtime-specific worker-ended event named by
WebWorkerHostOptions.exitEventName, which is not part of the webWorkerstandard and therefore has no handler slot. -
onerror: ((event: unknown) => void) | null
Error handler slot; events carry a
messagewhen available. -
onmessage: ((event: { data: unknown; }) => void) | null
Message handler slot; events carry the payload in
data. -
postMessage(message: unknown): void
Posts a structured-clonable message to the worker.
-
terminate(): void
Terminates the worker.
The shape of the ws module this adapter uses.
A ws WebSocketServer in noServer mode, narrowed to what this adapter
drives.
-
close(): void
Shuts the server down.
-
handleUpgrade(): voidrequest: unknown,socket: unknown,head: unknown,callback: (ws: WsSocketLike) => void
Completes the handshake over an already-accepted TCP connection.
A ws socket, narrowed to what this adapter drives. Declared structurally so
the package never takes a type dependency on @types/ws.
-
close(): voidcode?: number,reason?: string
Closes the socket.
-
on(): voidevent: string,listener: (...args: never[]) => void
Subscribes to a socket event.
-
readyState: number
Numeric ready state, matching the web WebSocket API's values.
-
send(data: string | Uint8Array): void
Sends a text or binary frame.
Usage
import * as RuntimePlugin_and_runtime_adapters_providing___linkcode_IRuntimeServices__for_Node_js__Deno__Bun__and_Cloudflare_Workers__HTTP_server_adapters_are_also_provided_for_running_the_framework_on_real_HTTP_servers___Every_export_is_documented_in_PUBLIC_API_md_section_36_ from "runtime/src/index.ts";