Skip to content

Commit 3d4eb19

Browse files
committed
Merged in [15448] from rjsparks@nostrum.com:
Add CORS headers for the api and views that serve json. Fixes ietf-tools#2546, ietf-tools#2551, and ietf-tools#2552. - Legacy-Id: 15453 Note: SVN reference [15448] has been migrated to Git commit 54d4844
2 parents 6dacd69 + 54d4844 commit 3d4eb19

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

ietf/settings.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ def skip_unreadable_post(record):
343343

344344
MIDDLEWARE = (
345345
'django.middleware.csrf.CsrfViewMiddleware',
346+
'corsheaders.middleware.CorsMiddleware', # see docs on CORS_REPLACE_HTTPS_REFERER before using it
346347
'django.middleware.common.CommonMiddleware',
347348
'django.contrib.sessions.middleware.SessionMiddleware',
348349
'django.contrib.auth.middleware.AuthenticationMiddleware',
@@ -382,6 +383,7 @@ def skip_unreadable_post(record):
382383
# External apps
383384
'anora',
384385
'bootstrap3',
386+
'corsheaders',
385387
'django_markup',
386388
'django_password_strength',
387389
'djangobwr',
@@ -455,6 +457,12 @@ def skip_unreadable_post(record):
455457

456458
}
457459

460+
# CORS settings
461+
# See https://github.com/ottoyiu/django-cors-headers/
462+
CORS_ORIGIN_ALLOW_ALL = True
463+
CORS_ALLOW_METHODS = ( 'GET', 'OPTIONS', )
464+
CORS_URLS_REGEX = r'^(/api/.*|.*\.json|.*/json/?)$'
465+
458466
# Override this in your settings_local with the IP addresses relevant for you:
459467
INTERNAL_IPS = (
460468
# local

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ defusedxml>=0.4.1 # for TastyPie when ussing xml; not a declared dependency
1313
Django>=1.11,<1.12
1414
django-bcrypt>=0.9.2 # for the BCrypt password hasher option. Remove when all bcrypt upgraded to argon2
1515
django-bootstrap3>=8.2.1,<9.0.0
16+
django-cors-headers>=2.4.0
1617
django-formtools>=1.0 # instead of django.contrib.formtools in 1.8
1718
django-markup>=1.1
1819
django-password-strength>=1.2.1

0 commit comments

Comments
 (0)