Tsoa: Custom middleware injection

Created on 20 Mar 2020  路  2Comments  路  Source: lukeautry/tsoa

How to inject custom middleware for certain routes ?

https://github.com/tarakeshp/stripe-node/blob/master/examples/webhook-signing/typescript-node-express/express-ts.ts
In the line number 34, bodyParser.raw({type: 'application/json'}) is a middleware injected in the request pipleline.

app.post(
'/webhook', bodyParser.raw({type: 'application/json'}),
(req: express.Request, res: express.Response): void => {
....
}

Likewise how can I pass to tsoa controller/action
@Post("subscriptions/webhook")
public async SubscriptionWebhook(@Request() httpContext: HttpContext): Promise {
......
}

Most helpful comment

I would like to inject into only specific routes and not for all. You are saying app.use method which is global injection for every request. But I wanted only for very specific routes and cant rely on path conditions.

Please look at the above code and also link mentioned.

All 2 comments

Any middleware registered before the RegisterRoutes(app) call should be applied.
You can use a global middleware that checks the url. However, there is currently no additional way tsoa supports to use middleware at the method/controller level.
If this doesn't solve your issue, please feel free to use the Issue template to open a new issue with more information.

Closing as duplicate of https://github.com/lukeautry/tsoa/issues/62

I would like to inject into only specific routes and not for all. You are saying app.use method which is global injection for every request. But I wanted only for very specific routes and cant rely on path conditions.

Please look at the above code and also link mentioned.

Was this page helpful?
0 / 5 - 0 ratings