CORS
CORS is a set of HTTP headers that lets a server share its responses with other origins. With the right headers, a script on another origin can read the response of a fetch() call.
Concept
Also called Cross-Origin Resource Sharing
Updated
On this page
Example
HTTP
# Request from a script on https://example.com Origin: https://example.com # Response from https://api.example.com Access-Control-Allow-Origin: https://example.com
The browser gives the response to the script only when the origin in the response matches.
How to set it
Send Access-Control-Allow-Origin with the origin that may read the response. Add the other headers only when you need them.
Access-Control-Allow-Origin: https://example.com Access-Control-Allow-Credentials: true Access-Control-Allow-Methods: GET, POST, PUT Access-Control-Allow-Headers: Content-Type
With credentials, such as cookies, the browser does not accept "*". Name the exact origin.
Learn more
Sources