Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing helmet instead of cors
Importing express instead of cors
Forgetting to import any middleware
✗ Incorrect
The cors package is imported to enable Cross-Origin Resource Sharing middleware.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using cors() instead of helmet()
Forgetting the parentheses after the middleware name
Using bodyParser instead of helmet
✗ Incorrect
Helmet is used to secure HTTP headers and is applied as middleware with app.use(helmet()).
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using boolean true or false instead of a string
Using null which disables CORS
Leaving origin undefined
✗ Incorrect
Setting origin: '*' allows all origins for CORS.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing cors instead of helmet
Using different names for import and usage
Forgetting parentheses when applying middleware
✗ Incorrect
You import helmet and then apply it with app.use(helmet()).
5fill in blank
hardFill 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'
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
✗ Incorrect
Enable CORS for https://example.com, then apply Helmet and CORS middleware.