Root _middleware is called for every request
See original GitHub issueI’m working on a session middleware which is called in the routes/_middleware.ts
to be able to access the session across the app.
As I see it, the root _middleware
is called for every request even the one outside the routes (e.g. static resource request, _frsh/alive, etc.) which could be the intended behavior as it’s consider a global middleware.
My issue is that with this behavior, it’s impossible to keep a session initialization in the root middleware and implement features like session flash as the multiple request expires the flashed data.
It could be possible to filter out from the request, but seems pretty unreliable.
Is it the expected behavior ? If so, maybe routes/_middleware
could be reserved only for request routed to a route, and we could find another way to implement global middlewares ?
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:6 (4 by maintainers)
Top GitHub Comments
Sounds like a good idea, I will see if I can make a PR for this 👍
Thanks for the idea @jcs224 , it seems like a nice solution for the time being.
I took some inspiration from your library to make a first draft of
fresh-session
but must have missed how you handle flash messages, love the work that you’ve done there.Thanks again for taking the time to point it out, really appreciate it 🙌