#Passing module options to the guard inside controller

6 messages · Page 1 of 1 (latest)

viscid pasture
#

Is it possible to pass module options to the guard inside controller? For example:

@Controller()
export class MyController {
  constructor(@Inject('MODULE_OPTIONS') private options: ModuleOptions) {}

  @MyGuardDecorator(options) // <- here
  //...
}
midnight bison
#

Why do you want to do this?

viscid pasture
# midnight bison Why do you want to do this?

My module has rate limiting options for each route. I need to pass them dynamically to the decorator in order to use them in guard. Something like this:

@Controller()
export class MyController {
  constructor(@Inject('MODULE_OPTIONS') private options: ModuleOptions) {}

  @MyGuardDecorator(options.rateLimiting.route1)
  //...

  @MyGuardDecorator(options.rateLimiting.route2)
  //...
}
midnight bison
#

for each route.

That would be per guard put on each route then? So, specialized guards for each route? Does each route definitely have a different rate limit? Sorry, but this makes little sense as it is. I need more context. Why do you wish to have possibly totally differing throttling config per route?

viscid pasture