0
0
NestJSframework~10 mins

CORS configuration 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 enable CORS in a NestJS application.

NestJS
const app = await NestFactory.create(AppModule);
app.[1]();
await app.listen(3000);
Drag options to blanks, or click blank then click option'
AenableCors
BstartCors
CuseCors
DactivateCors
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods like startCors or useCors which do not exist in NestJS.
Forgetting to call the method before app.listen.
2fill in blank
medium

Complete the code to allow CORS only from 'https://example.com'.

NestJS
const app = await NestFactory.create(AppModule);
app.enableCors({ origin: [1] });
await app.listen(3000);
Drag options to blanks, or click blank then click option'
A'https://example.com'
B'http://localhost:3000'
C'*'
D'https://myapp.com'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' which allows all origins instead of restricting.
Using a wrong URL or protocol.
3fill in blank
hard

Fix the error in this CORS configuration to allow credentials.

NestJS
app.enableCors({ origin: 'https://example.com', [1]: true });
Drag options to blanks, or click blank then click option'
AallowCredentials
BwithCredentials
Ccredentials
DenableCredentials
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'allowCredentials' or 'withCredentials' which are not valid options here.
Forgetting to set this option when credentials are needed.
4fill in blank
hard

Fill both blanks to configure CORS to accept GET and POST methods from any origin.

NestJS
app.enableCors({ origin: [1], methods: [2] });
Drag options to blanks, or click blank then click option'
A'*'
B['GET', 'POST']
C['PUT', 'DELETE']
D'https://example.com'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a specific origin instead of '*'.
Including methods not requested like PUT or DELETE.
5fill in blank
hard

Fill all three blanks to configure CORS with origin 'https://app.com', allow credentials, and only allow PUT method.

NestJS
app.enableCors({ origin: [1], credentials: [2], methods: [3] });
Drag options to blanks, or click blank then click option'
A'https://app.com'
Btrue
C['PUT']
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Setting credentials to false or a string.
Using wrong method names or multiple methods.
Using wildcard origin instead of specific URL.