Explain cross-origin resource sharing.
01
01
Understand the problem
cors
02
02
Attempt it yourself
Sketch your approach before reading the solution — that's what interviews test.
Stuck? AI Nudge Available
Get a conceptual hint to guide your logic without spoiling the final implementation.
03
03
Study the solution
The solution is waiting
Give it an honest attempt first — then compare your thinking with the full walkthrough.
04
04
Read the code
Cross-origin fetch + the headers that unblock it
// A page on https://app.com calling a different origin:
fetch("https://api.other.com/data")
.then((res) => res.json())
.then(console.log);
// The BROWSER only reveals the response if the server replies with:
// Access-Control-Allow-Origin: https://app.com (or *)
//
// For "non-simple" requests (PUT/DELETE, custom headers) the browser
// first sends a preflight OPTIONS request; the server must answer:
// Access-Control-Allow-Methods: PUT
// Access-Control-Allow-Headers: Content-Type
//
// To send cookies, the client uses { credentials: "include" } AND the
// server must set Access-Control-Allow-Credentials: true (origin can't be *).05
05
Join the discussion
Discussion (0)
Sign in to join the discussion.
No responses yet. Be the first to share what you think.