Bird
0
0

You have this middleware setup:

medium📝 Debug Q7 of 15
NestJS - Middleware
You have this middleware setup:
apply(loggingMiddleware, authMiddleware).forRoutes('admin')

But you want authMiddleware to execute before loggingMiddleware. What is the correct fix?
ASwap middleware inside loggingMiddleware
BChange to apply(authMiddleware, loggingMiddleware).forRoutes('admin')
CUse apply(authMiddleware).apply(loggingMiddleware).forRoutes('admin')
DNo change needed; order does not matter
Step-by-Step Solution
Solution:
  1. Step 1: Recognize middleware order

    Middleware run in the order they are passed to apply().
  2. Step 2: Swap middleware order

    To run authMiddleware first, it must be the first argument.
  3. Final Answer:

    apply(authMiddleware, loggingMiddleware).forRoutes('admin') -> Option B
  4. Quick Check:

    Order in apply() controls execution sequence [OK]
Quick Trick: Place middleware in apply() in desired run order [OK]
Common Mistakes:
  • Trying to chain apply() calls incorrectly
  • Modifying middleware internals instead of order
  • Assuming middleware order is automatic

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes