Bird
0
0

You want to allow requests from any subdomain of example.com and also from localhost. Which allowed_hosts list correctly configures TrustedHostMiddleware for this?

hard🚀 Application Q15 of 15
FastAPI - Middleware and Hooks
You want to allow requests from any subdomain of example.com and also from localhost. Which allowed_hosts list correctly configures TrustedHostMiddleware for this?
A['*.example.com', 'localhost']
B['example.com', 'localhost']
C['example.com/*', 'localhost']
D['*example.com', 'localhost']
Step-by-Step Solution
Solution:
  1. Step 1: Understand wildcard usage in allowed_hosts

    TrustedHostMiddleware supports wildcards like *.example.com to allow all subdomains.
  2. Step 2: Check each option for correct wildcard syntax

    ['*.example.com', 'localhost'] uses '*.example.com' which correctly matches all subdomains; others use incorrect patterns.
  3. Final Answer:

    ['*.example.com', 'localhost'] -> Option A
  4. Quick Check:

    Use '*.example.com' for subdomains = B [OK]
Quick Trick: Use '*.domain.com' to allow all subdomains [OK]
Common Mistakes:
MISTAKES
  • Using 'example.com/*' which is invalid
  • Using '*example.com' missing dot after *
  • Not using wildcard for subdomains

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes