Web / Traefik Interview questions
How do you configure CORS headers with Traefik middleware?
Cross-Origin Resource Sharing is handled with the Headers middleware, which can set Access-Control-Allow-Origin, allowed methods, allowed headers, and whether credentials are permitted, and can also automatically respond to preflight OPTIONS requests.
http: middlewares: cors: headers: accessControlAllowMethods: - GET - POST accessControlAllowOriginList: - "https://app.example.com" accessControlAllowCredentials: true
A frequent mistake is setting accessControlAllowOriginList to "*" together with accessControlAllowCredentials: true, which browsers reject outright, since wildcard origins and credentialed requests are mutually exclusive by the CORS spec itself.
The middleware also handles preflight caching through accessControlMaxAge, letting a browser skip repeating the OPTIONS round trip for a configured duration, which cuts down on chatty traffic for APIs called frequently from the same origin.
More Related questions...