Bird
0
0

What will happen if you call app.enableCors({ origin: 'https://example.com' }) in a NestJS app?

medium📝 component behavior Q5 of 15
NestJS - Middleware
What will happen if you call app.enableCors({ origin: 'https://example.com' }) in a NestJS app?
AThe app will throw a runtime error
BOnly requests from https://example.com will be allowed cross-origin access
CCORS will be disabled for all requests
DAll origins will be allowed to access the app
Step-by-Step Solution
Solution:
  1. Step 1: Understand the CORS origin option

    Setting origin to a specific URL restricts cross-origin requests to that URL only.
  2. Step 2: Analyze the effect on other origins

    Requests from other origins will be blocked by CORS policy. No error is thrown by NestJS.
  3. Final Answer:

    Only requests from https://example.com will be allowed cross-origin access -> Option B
  4. Quick Check:

    CORS origin option restricts allowed origins [OK]
Quick Trick: Set origin to allow only specific domains in CORS [OK]
Common Mistakes:
  • Assuming all origins are allowed by default
  • Thinking CORS disables all requests
  • Expecting runtime errors on origin mismatch

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes