Need help addressing cors issue on server
I have a django backend with react frontend. I am trying to deploy my application on cpanel hosting. I have created subdomain for backend (api.example.com/) and main domain (example.com/) is for frontend. PS: mentioned fake URL. Following is what my settings.py looks like,
INSTALLED_APPS = [
# Custom Installed
"corsheaders",
...
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
...
ALLOWED_HOSTS = [
'www.example.com',
'example.com',
'xxx.yyy.208.227',
]
# ALLOWED_HOSTS = ['*']
CORS_ORIGIN_ALLOW_ALL = False
# CORS_ALLOW_CREDENTIALS = True
CORS_ALLOWED_ORIGINS = [
'https://www.example.com',
'https://example.com',
'https://xxx.yyy.208.227',
]
I am seeing error as mentioned below,
Access to XMLHttpRequest at 'https://api.example.com/api/products/' from origin 'https://www.example.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Am I missing something?
In your settings, try replacing CORS_ORIGIN_ALLOW_ALL = True to CORS_ALLOW_ALL_ORIGINS = True.