0
0
NestJSframework~10 mins

Third-party middleware (cors, helmet) 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 import the CORS middleware in a NestJS application.

NestJS
import [1] from 'cors';
Drag options to blanks, or click blank then click option'
Acors
Bhelmet
Cexpress
DbodyParser
Attempts:
3 left
💡 Hint
Common Mistakes
Importing helmet instead of cors
Importing express instead of cors
Forgetting to import any middleware
2fill in blank
medium

Complete the code to apply Helmet middleware globally in the NestJS app.

NestJS
app.use([1]());
Drag options to blanks, or click blank then click option'
Acors
BbodyParser
Cexpress.json
Dhelmet
Attempts:
3 left
💡 Hint
Common Mistakes
Using cors() instead of helmet()
Forgetting the parentheses after the middleware name
Using bodyParser instead of helmet
3fill in blank
hard

Fix the error in enabling CORS with options in the NestJS app.

NestJS
app.enableCors({ origin: [1] });
Drag options to blanks, or click blank then click option'
A'*'
Btrue
Cfalse
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using boolean true or false instead of a string
Using null which disables CORS
Leaving origin undefined
4fill in blank
hard

Fill both blanks to import and apply Helmet middleware in main.ts.

NestJS
import [1] from 'helmet';

app.use([2]());
Drag options to blanks, or click blank then click option'
Ahelmet
Bcors
Dexpress
Attempts:
3 left
💡 Hint
Common Mistakes
Importing cors instead of helmet
Using different names for import and usage
Forgetting parentheses when applying middleware
5fill in blank
hard

Fill all three blanks to enable CORS with specific origin and apply Helmet middleware.

NestJS
app.enableCors({ origin: [1] });
app.use([2]());
app.use([3]());
Drag options to blanks, or click blank then click option'
A'https://example.com'
Bhelmet
Ccors
Dexpress
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' instead of a specific origin
Mixing up helmet and cors in usage order
Forgetting parentheses after middleware names