question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow middlewares to be applied after all controllers

See original GitHub issue

Feature 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jmcdo29commented, Aug 24, 2021

I’m not sure what you mean when you say bind it to interceptor,

Calling would have been a better word for me to use.

Is there a reason that this features is not implemented yet?

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.

1reaction
jmcdo29commented, Aug 23, 2021

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found