Closed jokull closed 11 months ago
Can't you do this with a middleware already?
const ctxStore = new AsyncLocalStorage<Context>();
app.use((ctx, next) => {
ctxStore.run(ctx, next);
})
or something similar
Let me try. I'll re-open if needed.
Any news on this?
I tried the example but it gave this error:
Error: Context is not finalized. You may forget returning Response object or `await next()`
Also tried it + a few variations and got the same error. Being able to provide a "context" for a request via AsyncLocalStorage would be very useful for using ParaglideJS with Hono.
Can this be reopened?
Using AsyncLocalStorge is a good idea. You can see the example middleware using it:
https://github.com/yusukebe/async-local-storage-middleware
Either way, we generally do not need it since we have a context.
Could be opt in.
https://developers.cloudflare.com/workers/runtime-apis/nodejs/asynclocalstorage/
If the Hono context object would be an AsyncLocalStorage you could retrieve whatever is inside it without passing
c
around. If you have a function somewhere and you want to, for example, elegantly handle a failure but log the error to Sentry, you would have to passc
potentially very deep down into you stack.