codejump

Custom Middleware

Preview — 3 of 10 questions

You want a lightweight middleware with no dependencies to inject. Which form is most appropriate?

AA plain function (req, res, next) => { ... } passed to consumer.apply()
BAn interceptor returned from @Module()
CA guard implementing canActivate
DA class implementing NestMiddleware registered in providers

What does consumer.apply(MiddlewareA, MiddlewareB).forRoutes('cats') do?

AOnly MiddlewareA runs; MiddlewareB is ignored
BBoth run on cats routes in the order they are listed: A then B
CThey run in reverse order: B then A
DThey run in parallel with no ordering guarantee

How do you apply a middleware to all controller routes except cats/health?

Aconsumer.apply(M).forRoutes('cats').not('cats/health')
Bconsumer.apply(M).forRoutes('cats/*').skip('cats/health')
CExclusion is impossible; you must list every included route
Dconsumer.apply(M).exclude('cats/health').forRoutes(CatsController)

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.