Recall & Review
beginner
What does CORS stand for and why is it important in web development?
CORS stands for Cross-Origin Resource Sharing. It is important because it controls how resources on a web server can be requested from another domain, helping to keep web applications secure by preventing unauthorized access.
Click to reveal answer
beginner
How do you enable CORS in a NestJS application?
You enable CORS in NestJS by calling the
enableCors() method on the app instance, usually in the main.ts file, like app.enableCors(). You can also pass options to customize the behavior.Click to reveal answer
intermediate
What is the purpose of the
origin option in NestJS CORS configuration?The
origin option specifies which domains are allowed to access the server resources. It can be a string, an array of strings, or a function to dynamically allow or deny requests from certain origins.Click to reveal answer
intermediate
How can you restrict CORS to allow only specific HTTP methods in NestJS?
You can restrict allowed HTTP methods by setting the
methods option in the enableCors() configuration, for example: app.enableCors({ methods: ['GET', 'POST'] }).Click to reveal answer
beginner
What happens if you do not configure CORS in a NestJS API that is accessed from a different domain?
If CORS is not configured, browsers will block requests made from different domains for security reasons. This means your frontend app on another domain won't be able to access your NestJS API.
Click to reveal answer
Which NestJS method is used to enable CORS?
✗ Incorrect
The correct method to enable CORS in NestJS is app.enableCors().
What does the 'origin' option in CORS configuration control?
✗ Incorrect
The 'origin' option controls which domains are allowed to access the server resources.
If you want to allow only GET and POST requests from other domains, which option should you set?
✗ Incorrect
The correct option is 'methods' to specify allowed HTTP methods in CORS.
What will happen if CORS is not enabled on a NestJS API accessed from a different domain?
✗ Incorrect
Browsers block cross-origin requests if CORS is not enabled for security.
Can the 'origin' option in NestJS CORS configuration accept a function?
✗ Incorrect
The 'origin' option can be a function to dynamically control allowed origins.
Explain how to enable and customize CORS in a NestJS application.
Think about the main.ts file and the enableCors method.
You got /4 concepts.
Describe what problems CORS solves and what happens if it is not configured properly in NestJS.
Consider browser security and cross-origin requests.
You got /4 concepts.