adamchainz / django-cors-headers

Django app for handling the server headers required for Cross-Origin Resource Sharing (CORS)
MIT License
5.4k stars 536 forks source link

CORS Header error when trying to query a Django graphene Graphql API #683

Closed JoshuaFurman closed 3 years ago

JoshuaFurman commented 3 years ago

Python Version

3.8.2

Django Version

3.2.7

Package Version

3.8.0

Description

I have a Graphql API built with Django and graphene, it's hosted on Heroku. I can query the API perfectly fine with Postman and can even pull up the graphiql interface and make queries like that. However, I'm trying to create a frontend using React with the Apollo Client and when I try to load my frontend that just makes a simple request I'm getting 2 errors in the Devtools:

Screen Shot 2021-09-11 at 12 24 32 PM

Anyone know what the issue is? I'm happy to supply more info if needed.

I have my django-corsheaders settings configured correctly according to the README here so I'm not sure what's going wrong... This could be an issue with the React Apollo Client, if so I'll gladly remove this issue and create one there.

adamchainz commented 3 years ago

I have my django-corsheaders settings configured correctly according to the README here so I'm not sure what's going wrong...

by that you mean you have http://localhost:3000 as an allowed origin?

JoshuaFurman commented 3 years ago

In my settings I have: CORS_ALLOW_ALL_ORIGINS = True CORS_ALLOW_CREDENTIALS = True

I now have it working from http://localhost:3000 (my local frontend server) and the same frontend deployed to separate Heroku app. I think the error came from Heroku not reading/setting the Environment variables from my Django project settings.py correctly...

Thanks for your quick response!