Recall & Review
beginner
What is CORS in web development?
CORS stands for Cross-Origin Resource Sharing. It is a security feature that allows or blocks web pages from making requests to a different domain than the one that served the web page.
Click to reveal answer
beginner
How do you install the CORS middleware in an Express app?
You install it using npm with the command <code>npm install cors</code>. Then you import it in your app with <code>import cors from 'cors'</code> or <code>const cors = require('cors')</code>.Click to reveal answer
beginner
How do you enable CORS for all routes in an Express app?
You use the CORS middleware globally by adding
app.use(cors()) before your routes. This allows all origins to access your server.Click to reveal answer
intermediate
How can you restrict CORS to allow only specific origins?
You pass an options object to the CORS middleware like
app.use(cors({ origin: 'https://example.com' })). This allows only requests from that origin.Click to reveal answer
intermediate
What is the purpose of the
optionsSuccessStatus option in CORS middleware?It sets the status code for successful OPTIONS preflight requests. Some browsers expect a 200 status instead of the default 204, so you can set
optionsSuccessStatus: 200 to fix issues.Click to reveal answer
What does the CORS middleware do in an Express app?
✗ Incorrect
CORS middleware controls which external domains can access your server resources.
How do you apply CORS middleware to all routes in Express?
✗ Incorrect
Using app.use(cors()) applies the middleware globally to all routes.
Which npm command installs the CORS middleware?
✗ Incorrect
The CORS middleware is installed with npm install cors.
How do you restrict CORS to only allow requests from 'https://myapp.com'?
✗ Incorrect
The origin option specifies which domain is allowed.
What HTTP method is commonly used for CORS preflight requests?
✗ Incorrect
Browsers send OPTIONS requests to check permissions before the actual request.
Explain how to set up CORS middleware in an Express app to allow all origins.
Think about the steps from installation to applying middleware globally.
You got /4 concepts.
Describe how to configure CORS middleware to restrict access to a specific domain.
Focus on the options object passed to the middleware.
You got /3 concepts.