Hono for service worker routing: how to return a response from Cache storage? #4515
Unanswered
marceloomens
asked this question in
Q&A
Replies: 1 comment
-
|
I stumbled across this while trying to solve the same issue. This works for me: app.use("*", async (c, next) => {
const cache = await caches.open(CACHE_NAME)
const match = await cache.match(c.req.url)
if (match) {
console.log("cache match", match)
return match
}
await next()
})This allows my assets to be served from the cache while the service worker routes are served by their respective |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The context compiles a
Responseobject before handing it off to the fetch event handler of theServiceWorkerGlobalScope. In my case, this fetch event handler is initialized withfire()fromhono/service-worker.My use case is the following. In my route handler, I'm fetching a pre-cached
Responseobject from cache storage. How do I merge thisResponseobject with the current context? Is there a way to preserve / merge the response object with the response that's currently "under construction" in the current context?In my code above, I'm merely handing off the response's body, ignoring all the other parts of the response (including status code, response headers, etc.)
N.B.
I do like how I seem to be able to provide a ReadableStream to
c.body()rather than a string.Beta Was this translation helpful? Give feedback.
All reactions