Kind: Function
Source: src/adapter/service-worker/handler.ts
Part of: Adapter
Adapter for Service Worker
handle adapts Service Worker fetch events to the application's request handler. It receives an incoming request, runs it through the adapter flow, and returns the response used by the Service Worker.
Signature
tsfunction handle(app: Hono<E, S, BasePath>, opts: HandleOptions): Handler
Parameters
| Name | Type |
|---|---|
app | Hono<E, S, BasePath> |
opts | HandleOptions |
Returns: Handler
Diagram
mermaidgraph LR FetchEvent[Service Worker fetch event] --> Request[Request] Request --> Handle[handle] Handle --> App[Application handler] App --> Response[Response] Response --> FetchEvent
Usage
tsimport { handle } from './handler'
self.addEventListener('fetch', (event) => {
event.respondWith(handle(event.request))
})
AI Coding Instructions
- Keep the Service Worker adapter focused on converting incoming requests into application handler calls.
- Return the handler response directly so
fetchevents receive a validResponse. - Register
handlethroughevent.respondWith(...)when wiring Service Worker fetch events. - Do not add browser window APIs to this module; Service Worker code runs in a worker context.
Was this page helpful?