denoland / fresh

The next-gen web framework.
https://fresh.deno.dev
MIT License
12.05k stars 607 forks source link

Provide possibility to run plugin middleware before middlewares under `routes/` #2160

Open maxbrieiev opened 7 months ago

maxbrieiev commented 7 months ago

It would be good to have the possibility to run plugin middlewares before middlewares defined inside routes/ directory.

One use case is to provide a pluggable authentication through plugins, so that a middleware inside the routes/ folder could expect the session object to be available.

deer commented 7 months ago

Thanks for logging this, since I had already started thinking about a related issue. I was thinking of the case of absolutely ordering middleware from plugins (imagine two different plugins provide middleware and one should run first), instead of just plugin vs normal middleware.

For plugins which statically declare middleware, we should be able to extract these and allow the user to order them as wanted. If any ordering is provided, we can interpret that as higher priority than routes.