Replies: 2 comments
-
Hey @Vesafary! Unfortunately, you cannot use individual middlewares per I'm interested in understanding the use case for why you need middleware per Router. Perhaps you are organizing your routes based on a specific logic, such as domain/entities/others, and you would like to apply the same Middleware to all routes in this case? |
Beta Was this translation helpful? Give feedback.
-
Hi @leandrodamascena! Thanks for your answer. There's a couple of reasons. The most important one to us: our application has a role-based authentication system (which is primarily handled by an API Gateway Authoriser), but a couple of endpoints have either role-based logic (e.g. an admin would fetch more (deleted) objects than a normal user) or instance-based logic (e.g. only the creator of an item is able to see it, or when the creator decides to share it). In these cases, a gateway authoriser can't do much more than accept the request, and the authentication has to be handled by the backend. This is what we're trying to do with a middleware, but to avoid someone forgetting to add it to a route (as per your example), or setting the wrong one, and to avoid code duplication and upon a refactor having to change dozens of endpoints, we want to add it globally as a "default" instead of on a per endpoint basis. However, that runs into the issue that some requests (e.g. OPTIONS, /swagger, some custom ones) have to be open-access. In my opinion, the nicest and easiest solution was to use multiple routers. BTW, as a follow-up it would also be nice if we could nest routers. Right now, you can only include a router on the app-level with a prefix, but not on another one. Usecase for this would be even further separation and less repetition between multiple domains. |
Beta Was this translation helpful? Give feedback.
-
Let's say I have multiple Routers to split routes, is it possible to give each router its own global middleware?
Right now, in my test setup, it seems like they are all piled together:
Beta Was this translation helpful? Give feedback.
All reactions