Allow middlewares to be applied after all controllers
See original GitHub issueFeature Request
Is your feature request related to a problem?
This issue is already mentioned in #284 however in this case I’m having problem with services that requires their handlers to be used after all controllers (which are not developed by myself).
Take Sentry.io for example, It perfectly works with express but not with NestJs because its error handler middleware must be applied after all controllers.
The problem is that NestJs applies all middlewares before controllers no matter what, If there was a feature to fix that, then using services like Sentry would be easier which eliminates the need to use a third party package or maintaining my own hack.
Describe the solution you’d like
Not sure but maybe something like this:
app.useAfter(middleware);
What is the motivation / use case for changing the behavior?
More flexibility around using middlewares.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
c# - Use Middleware for some controllers - Stack Overflow
In my ASP Net Core application I need to apply a custom Middleware only for specific controller. app. UseWhen(context => context. Request.
Read more >Conditional Middleware based on request in ASP.NET Core
This post looks at how to configure ASP.NET Core middleware in a way that allows you to have different middleware for different types...
Read more >Register Express middleware per route, controller class or ...
Per controller class This allows developers to apply the same set of middleware for multiple routes. @use(requireAuthenticated()) class ...
Read more >How Controllers and Middleware Work in Laravel - Cloudways
All middleware in Laravel are created in the Middleware folder, located inside the `app/HTTP` folder.
Read more >ASP.NET Core Middleware | Microsoft Learn
Authentication Middleware (UseAuthentication) attempts to authenticate the user before they're allowed access to secure resources. Authorization ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Calling would have been a better word for me to use.
Because there’s already interceptors, which can make this work pretty much as you’ve seen. It’s not often that you need post-request middleware other than error handlers (exception filters), loggers (interceptors) and response mappers (also interceptors). There’s already a good bit of complexity in how the proxy around express and fastify is set up, and managing another middleware layer between post-controller and response sent would be more to worry about in making the codebase more complex.
What about binding the error handler via an interceptor? Similar to how Nest has in the before section for multer in the
FileInterceptor
? At the moment, we aren’t planning on allowing for post-request middleware