How to use custom middleware?
See original GitHub issueCurrently, we are moving a lot of non business logic in middleware and using them per route, for example:
router.post('/some/path', accountValidator, userValidator, prometheusMetrics, someOtherMiddleware, myController.getSomethingUseful);
How can i add custom middlewares to automatically generated routes.ts? Are there any other ways like custom decorators or base controller that I should consider using with tsoa? I think I’m fine migrating custom middlewares to something else but I don’t understand what is an alternative tsoa way of doing this?
Sorting
-
I’m submitting a …
- bug report
- feature request
- support request
-
I confirm that I
- used the search to make sure that a similar issue hasn’t already been submit
Expected Behavior
I expected to find some
@Middleware
decorator or a guide how to create custom decorators
Current Behavior
@Route decorator doesn’t have options parameter where i could add functions or middleware to execute before or after main haindler
Possible Solution
- add an options to @Route (‘/my/path’, { before: promMetrics } )
- add a custom @Middleware decorator
- add a documentation how to add custom shareable code
- Confirm you were using yarn not npm: [ npm]
Issue Analytics
- State:
- Created 2 years ago
- Reactions:13
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Write custom ASP.NET Core middleware - Microsoft Learn
using System.Globalization; var builder = WebApplication.CreateBuilder(args); var app = builder.Build(); app.UseHttpsRedirection(); app.
Read more >Add custom middleware in ASP.NET Core application
Select Middleware Class item and give it a name and click on Add button. This will add a new class for the middleware...
Read more >Create Custom Middleware In An ASP.NET Core Application
Creating the Custom Middleware component · using System.Diagnostics; · using System.IO; · using System.Threading.Tasks; · using Microsoft.AspNetCore ...
Read more >Custom Middleware in ASP.NET Core - Dot Net Tutorials
Step2: Registering the Custom Middleware in the HTTP Request Processing Pipeline · void Configure(IApplicationBuilder app, IWebHostEnvironment env) · { · Use(async ...
Read more >Middleware in ASP.NET 6 - Custom Middleware Classes
Let's create a custom middleware class that does the same thing. Basics of a Middleware Class. Here's a basic empty class we'll use...
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 FreeTop 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
Top GitHub Comments
Sounds like I’m late to the party, but in my company we want to use
tsoa
and would really love to be able to use custom middlewares, so I made a PR to do just that, and I would love some feedback.Were you able to resolve the issue?