Complete the code to enable CORS in an Express app.
const express = require('express'); const cors = require('[1]'); const app = express(); app.use(cors()); app.listen(3000);
The cors package is used to enable CORS in Express apps.
Complete the code to allow only requests from 'https://example.com'.
app.use(cors({ origin: '[1]' }));Setting origin to 'https://example.com' restricts access to that domain only.
Fix the error in the CORS setup to allow credentials.
app.use(cors({ origin: 'https://myapp.com', credentials: [1] }));The credentials option expects a boolean true, not a string.
Fill both blanks to restrict CORS to GET and POST methods only.
app.use(cors({ methods: ['[1]', '[2]'] }));Specifying methods limits allowed HTTP methods to GET and POST.
Fill all three blanks to create a CORS config that allows origin 'https://site.com', credentials, and only GET method.
app.use(cors({ origin: '[1]', credentials: [2], methods: ['[3]'] }));This config allows only 'https://site.com' origin, sends credentials, and permits only GET requests.
