0
0
Expressframework~10 mins

cors middleware setup in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the CORS middleware.

Express
const cors = require('[1]');
Drag options to blanks, or click blank then click option'
Aexpress
Bcors
Chttp
Dbody-parser
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'express' instead of 'cors' in require statement.
Forgetting to import the CORS middleware.
2fill in blank
medium

Complete the code to apply CORS middleware globally in the Express app.

Express
app.use([1]());
Drag options to blanks, or click blank then click option'
Acors
Bexpress
CbodyParser
Dhelmet
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'express()' instead of 'cors()' in app.use.
Not calling the middleware function with parentheses.
3fill in blank
hard

Fix the error in the CORS options object to allow only requests from 'https://example.com'.

Express
app.use(cors({ origin: [1] }));
Drag options to blanks, or click blank then click option'
Afalse
B'*'
Ctrue
D'https://example.com'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' allows all origins, not just the specific one.
Using boolean values instead of a string URL.
4fill in blank
hard

Fill both blanks to configure CORS to allow credentials and restrict origin to 'https://myapp.com'.

Express
app.use(cors({ origin: [1], [2]: true }));
Drag options to blanks, or click blank then click option'
A'https://myapp.com'
B'*'
Ccredentials
Dmethods
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' for origin when restricting to a specific domain.
Using 'methods' instead of 'credentials' to allow credentials.
5fill in blank
hard

Fill all three blanks to create a CORS middleware that allows origin 'https://site.com', credentials, and only GET and POST methods.

Express
app.use(cors({ origin: [1], [2]: true, [3]: ['GET', 'POST'] }));
Drag options to blanks, or click blank then click option'
A'https://site.com'
Bcredentials
Cmethods
D'*'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' for origin when restricting to a specific domain.
Omitting the credentials option when cookies are needed.
Using incorrect option names like 'methodsAllowed' instead of 'methods'.