Skip to main content
doc0blade47/honodocumentation home
Sign in

Runtime Adapters

Last updated Oct 12, 2026
Relevant source files

The following files were used as context for generating this wiki page:

Overview

Runtime Adapters bridge Hono's Web Standard-based Application Core and Execution Context with platform-specific execution environments, request event structures, bindings, and asset-serving facilities. Different serverless, edge, and worker runtimes utilize disparate native entry points, event signatures, and connection metadata mechanisms that diverge from standard fetch event flows. Hono's adapter subsystems translate these proprietary structures into clean Web Standard Request and Response objects, expose secure connection info, and integrate environment bindings seamlessly.

Sources: src/adapter/cloudflare-pages/handler.ts:32-46


AWS Lambda Adapters

The AWS Lambda-Edge adapter processes CloudFront edge events (CloudFrontEdgeEvent) by mapping incoming CloudFront request structures into a Web Standard Request object. When an incoming request carries a query string, host header, or body data (including base64-encoded payloads via decodeBase64), createRequest reconstructs a full URL and populates request headers.

Sources: src/adapter/lambda-edge/handler.ts:116-138, src/adapter/lambda-edge/handler.ts:152-184

The execution flow transforms responses back into CloudFront-compatible formats through createResult. If the response content type indicates binary data according to isContentTypeBinary, the body is encoded using encodeBase64 from array buffers, setting bodyEncoding: 'base64'.

export const isContentTypeBinary = (contentType: string): boolean => {
  return !/^(text\/(plain|html|css|javascript|csv).*|application\/(.*json|.*xml).*|image\/svg\+xml.*)$/.test(
    contentType
  )
}

Sources: src/adapter/lambda-edge/handler.ts:140-150, src/adapter/lambda-edge/handler.ts:202-206


Cloudflare Adapters

Cloudflare runtime adapters support both Cloudflare Workers (workerd) and Cloudflare Pages. The Cloudflare Workers adapter exposes module-based static asset handling via getContentFromKVAsset, WebSocket upgrading through upgradeWebSocket, and remote IP retrieval via getConnInfo. Static asset request flows are executed through the call chain module (in serve-static-module.ts) delegating to serveStatic (in serve-static.ts), which in turn invokes the base serveStatic middleware to resolve MIME types and decode URIs.

Sources: src/adapter/cloudflare-workers/serve-static-module.ts:6-10, src/adapter/cloudflare-workers/serve-static.ts:21-42, src/middleware/serve-static/index.ts:35-126

Cloudflare Pages adapters provide handle for routing Pages Functions and handleMiddleware for executing individual middleware layers against EventContext. The serveStatic helper inside Cloudflare Pages queries env.ASSETS.fetch directly to serve assets from advanced mode configurations.

export const serveStatic = (): MiddlewareHandler => {
  return async (c) => {
    const env = c.env as { ASSETS: FetcherLike }
    const res = await env.ASSETS.fetch(c.req.raw)
    if (res.status === 404) {
      return c.notFound()
    }
    return res
  }
}

Sources: src/adapter/cloudflare-pages/handler.ts:32-46, src/adapter/cloudflare-pages/handler.ts:114-123


Edge and Serverless Adapters

Edge and serverless adapters unify other hosting providers like Vercel, Netlify, and generic Service Workers. The Vercel adapter exports a minimal request handler that forwards incoming requests directly to app.fetch(req).

Sources: src/adapter/vercel/handler.ts:4-8, src/adapter/netlify/handler.ts:4-10

Similarly, the Netlify adapter wraps requests into Hono execution calls with binding contexts. Service worker handlers listen for fetch events (addEventListener('fetch')), invoking app.fetch with execution contexts and falling back to global fetch operations on 404 statuses if configured.

export const handle = <E extends Env, S extends Schema, BasePath extends string>(
  app: Hono<E, S, BasePath>,
  opts: HandleOptions = {
    fetch: globalThis.fetch.bind(globalThis),
  }
): Handler => {
  return (evt) => {
    evt.respondWith(
      (async () => {
        const res = await app.fetch(evt.request, {}, evt)
        if (opts.fetch && res.status === 404) {
          return await opts.fetch(evt.request)
        }
        return res
      })()
    )
  }
}

Sources: src/adapter/service-worker/handler.ts:18-36, src/adapter/service-worker/index.ts:28-34


Runtime Detection and Environment Helper

The adapter helper module provides runtime detection and environment binding resolution via getRuntimeKey() and env(c). getRuntimeKey() inspects navigator.userAgent, global objects (EdgeRuntime, fastly), and process.release.name to categorize the host engine into a recognized Runtime type.

Runtime KeyDetection ConditionEnvironment Source
denonavigator.userAgent starts with 'Deno'Deno.env.toObject()
bunnavigator.userAgent starts with 'Bun'globalEnv (process.env)
workerdnavigator.userAgent starts with 'Cloudflare-Workers'c.env
nodeglobal.process.release.name === 'node'globalEnv (process.env)
edge-lighttypeof global.EdgeRuntime === 'string'globalEnv (process.env)
fastlyglobal.fastly !== undefined{}
otherFallback when undetected{}

Sources: src/helper/adapter/index.ts:8-41, src/helper/adapter/index.ts:43-84

Was this page helpful?