Add CORS headers for the api and views that serve json. Fixes #2546, #2551, and #2552. Commit ready for merge.

- Legacy-Id: 15448
This commit is contained in:
Robert Sparks 2018-09-11 20:04:35 +00:00
parent d9b53a5d6c
commit 54d484493c
2 changed files with 9 additions and 0 deletions

View file

@ -343,6 +343,7 @@ if DEBUG:
MIDDLEWARE = ( MIDDLEWARE = (
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
'corsheaders.middleware.CorsMiddleware', # see docs on CORS_REPLACE_HTTPS_REFERER before using it
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
@ -382,6 +383,7 @@ INSTALLED_APPS = (
# External apps # External apps
'anora', 'anora',
'bootstrap3', 'bootstrap3',
'corsheaders',
'django_markup', 'django_markup',
'django_password_strength', 'django_password_strength',
'djangobwr', 'djangobwr',
@ -455,6 +457,12 @@ BOOTSTRAP3 = {
} }
# CORS settings
# See https://github.com/ottoyiu/django-cors-headers/
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_METHODS = ( 'GET', 'OPTIONS', )
CORS_URLS_REGEX = r'(^/api/.*|^.*json)$'
# Override this in your settings_local with the IP addresses relevant for you: # Override this in your settings_local with the IP addresses relevant for you:
INTERNAL_IPS = ( INTERNAL_IPS = (
# local # local

View file

@ -13,6 +13,7 @@ defusedxml>=0.4.1 # for TastyPie when ussing xml; not a declared dependency
Django>=1.11,<1.12 Django>=1.11,<1.12
django-bcrypt>=0.9.2 # for the BCrypt password hasher option. Remove when all bcrypt upgraded to argon2 django-bcrypt>=0.9.2 # for the BCrypt password hasher option. Remove when all bcrypt upgraded to argon2
django-bootstrap3>=8.2.1,<9.0.0 django-bootstrap3>=8.2.1,<9.0.0
django-cors-headers>=2.4.0
django-formtools>=1.0 # instead of django.contrib.formtools in 1.8 django-formtools>=1.0 # instead of django.contrib.formtools in 1.8
django-markup>=1.1 django-markup>=1.1
django-password-strength>=1.2.1 django-password-strength>=1.2.1