Zappa
Zappa copied to clipboard
[Migrated] CORS is blocked despite it is enabled in settings file
Originally from: https://github.com/Miserlou/Zappa/issues/1867 by goktugerce
I enabled CORS in zappa_settings.json
file with "cors": true
, but I am still getting CORS errors.
Context
This is a React application. The console log is as follows: Access to fetch at 'URL' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response.
I have been using the same settings for my previous deployment. I had to undeploy it and deploy it again, but all of a sudden I started getting the error above.
Expected Behavior
The expected behavior is to allow CORS requests.
Actual Behavior
Actual behavior is seen in the error log above.
Steps to Reproduce
This is the settings seen in API Gateway:
'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'
This is how I am sending the fetch request in React:
const customHeader = () => ({
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Content-Type,Authorization',
Accept: 'application/json',
Authorization: 'Bearer ' + localStorage.getItem('id_token') || undefined,
});
fetch(`${baseUrl}${url}`, {
method,
headers: customHeader(),
body: JSON.stringify(data),
})
.then(response => response.json())
Your Environment
It's possible your application's the reason for blocking the CORS.
Hi there! Unfortunately, this Issue has not seen any activity for at least 90 days. If the Issue is still relevant to the latest version of Zappa, please comment within the next 10 days if you wish to keep it open. Otherwise, it will be automatically closed.
Hi there! Unfortunately, this Issue was automatically closed as it had not seen any activity in at least 100 days. If the Issue is still relevant to the latest version of Zappa, please open a new Issue.