Overcoming CORS Issues
suggest changeSet these headers on the response. Access-Control-Allow-Origin: * cannot be combined with credentials; browsers reject that pair. Name the calling origin when the browser should send cookies.
// Origin you want to allow. Do not use '*' when credentials are enabled.
response.setHeader('Access-Control-Allow-Origin', 'https://example.com');
// Request methods you wish to allow
response.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
response.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
response.setHeader('Access-Control-Allow-Credentials', 'true');
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents