0
0
NestJSframework~10 mins

Middleware ordering in NestJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to apply middleware globally in NestJS.

NestJS
app.[1](LoggerMiddleware);
Drag options to blanks, or click blank then click option'
Ause
Bapply
Cregister
Dadd
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'apply' or 'register' which are not valid methods for middleware application.
Confusing middleware application with module registration.
2fill in blank
medium

Complete the code to apply middleware only to a specific route.

NestJS
consumer
  .apply(AuthMiddleware)
  .forRoutes({ path: '[1]', method: RequestMethod.GET });
Drag options to blanks, or click blank then click option'
A/auth
B/users
C/products
D/orders
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a route unrelated to user authentication.
Using a route that does not exist in the example.
3fill in blank
hard

Fix the error in the middleware order to ensure LoggerMiddleware runs before AuthMiddleware.

NestJS
consumer
  .apply([1], AuthMiddleware)
  .forRoutes('*');
Drag options to blanks, or click blank then click option'
ACorsMiddleware
BAuthMiddleware
CLoggerMiddleware
DCompressionMiddleware
Attempts:
3 left
💡 Hint
Common Mistakes
Placing AuthMiddleware before LoggerMiddleware.
Using unrelated middleware in the order.
4fill in blank
hard

Fill both blanks to apply two middlewares in correct order for all routes.

NestJS
consumer
  .apply([1], [2])
  .forRoutes('*');
Drag options to blanks, or click blank then click option'
ALoggerMiddleware
BAuthMiddleware
CCorsMiddleware
DCompressionMiddleware
Attempts:
3 left
💡 Hint
Common Mistakes
Reversing the middleware order.
Using unrelated middleware.
5fill in blank
hard

Fill all three blanks to apply three middlewares in order: Logger, Auth, then Cors for all routes.

NestJS
consumer
  .apply([1], [2], [3])
  .forRoutes('*');
Drag options to blanks, or click blank then click option'
AAuthMiddleware
BLoggerMiddleware
CCorsMiddleware
DCompressionMiddleware
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing the order of middleware.
Using CompressionMiddleware instead of CorsMiddleware.