Import
Functions
serveStatic()
Middleware for serving static files from Cloudflare Workers KV.Parameters
options.manifest-object | string- Asset manifest for KVoptions.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 receivedonClose- Called when the connection closesonError- 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-ipheader to identify the client’s IP address - WebSocket connections require special handling with
WebSocketPair - The
onOpenevent is not available for WebSockets in Cloudflare Workers - Static file serving is deprecated in favor of Cloudflare Static Assets or Cloudflare Pages