Skip to main content
The Cloudflare Workers adapter provides utilities for running Hono applications on Cloudflare Workers.

Import

Functions

serveStatic()

serveStatic in the Cloudflare Workers adapter is deprecated. You can serve static files directly using Cloudflare Static Assets.Cloudflare Static Assets is currently in open beta. If this doesn’t work for you, please consider using Cloudflare Pages. You can start to create the Cloudflare Pages application with the npm create hono@latest command.
Middleware for serving static files from Cloudflare Workers KV.

Parameters

  • options.manifest - object | string - Asset manifest for KV
  • options.namespace - KVNamespace (optional) - KV namespace to use
  • Additional options from base ServeStaticOptions

Example

upgradeWebSocket()

Helper function to upgrade HTTP connections to WebSocket connections in Cloudflare Workers.

Parameters

  • createEvents - Function that receives context and returns WebSocket event handlers:
    • onMessage - Called when a message is received
    • onClose - Called when the connection closes
    • onError - Called on error
Cloudflare Workers doesn’t support the onOpen event. The connection is established after the handler returns.

Example

getConnInfo()

Extracts connection information from the Cloudflare Workers request.

Returns

Example

Platform-Specific Notes

  • Cloudflare Workers uses the cf-connecting-ip header to identify the client’s IP address
  • WebSocket connections require special handling with WebSocketPair
  • The onOpen event is not available for WebSockets in Cloudflare Workers
  • Static file serving is deprecated in favor of Cloudflare Static Assets or Cloudflare Pages

See Also