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.

How to use custom middleware?

See original GitHub issue

Currently, 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:closed
  • Created 2 years ago
  • Reactions:13
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
cheng81commented, Nov 4, 2021

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.

4reactions
panwauucommented, Oct 1, 2021

Were you able to resolve the issue?

Read more comments on GitHub >

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

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