I’m trying to connect a django Rest API to a react project, the API is deployed to heroku and seems to be working as intended, but when trying to signup on my react project I’m getting the following error message in the console:
Access to XMLHttpRequest at ‘https://productive-you-api-d9afbaf8a80b.herokuapp.com/dj-rest-auth/registration/’ from origin ‘https://3000-leighallend-productivey-5rpfnq7ldhc.ws.codeinstitute-ide.net’ has been blocked by CORS policy: Request header field content-tye is not allowed by Access-Control-Allow-Headers in preflight response.
My cors section in the api’s settings.py file is this:
CORS_ALLOWED_ORIGINS = []
CORS_ALLOWED_ORIGIN_REGEXES = [
r"^https://.*.gitpod.io$",
r".codeinstitute-ide.net$",
]
if 'CLIENT_ORIGIN' in os.environ:
CORS_ALLOWED_ORIGINS = [
os.environ.get('CLIENT_ORIGIN')
]
else:
CORS_ALLOWED_ORIGINS.extend([
'https://3000-leighallend-productivey-5rpfnq7ldhc.ws.codeinstitute-ide.net',
'https://productive-you-api-d9afbaf8a80b.herokuapp.com',
])
CORS_ALLOW_CREDENTIALS = True
CORS_ALLOW_HEADERS = list(default_headers) + [
'Content-Type',
]
I have no idea what any of this means
I tried to connect my api to the react project as done in a tutorial for my course with Code Institute, I expected to be able to create a user but my corsheaders are causing issues.