From f47f4acde1e8ca161216539094781c382cffe20d Mon Sep 17 00:00:00 2001 From: Tuomas Suutari Date: Tue, 26 Sep 2017 15:58:19 +0300 Subject: [PATCH] Configure CORS headers for the dashboard Add Cross-Origin Resources Sharing (CORS) HTTP headers to the responses so that web browsers allow access to the API endpoints from different domains too. --- parkkihubi/settings.py | 3 +++ requirements.in | 1 + requirements.txt | 1 + 3 files changed, 5 insertions(+) diff --git a/parkkihubi/settings.py b/parkkihubi/settings.py index cb0be44b..49327707 100644 --- a/parkkihubi/settings.py +++ b/parkkihubi/settings.py @@ -71,6 +71,7 @@ 'django.contrib.staticfiles', 'django.contrib.gis', 'raven.contrib.django.raven_compat', + 'corsheaders', 'rest_framework', 'rest_framework.authtoken', 'rest_framework_gis', @@ -88,6 +89,7 @@ ############## MIDDLEWARE = [ 'django.contrib.sessions.middleware.SessionMiddleware', + 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'parkkihubi.middleware.AdminTimezoneMiddleware', @@ -164,6 +166,7 @@ 'TEST_REQUEST_DEFAULT_FORMAT': 'json', } +CORS_ORIGIN_ALLOW_ALL = True ############## # Parkkihubi # diff --git a/requirements.in b/requirements.in index 7a35fe74..19bbef0c 100644 --- a/requirements.in +++ b/requirements.in @@ -23,3 +23,4 @@ owslib # Misc pytz +django-cors-headers diff --git a/requirements.txt b/requirements.txt index 28f1ba8c..89f0c18c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ certifi==2018.1.18 # via requests chardet==3.0.4 # via requests django==1.11.9 +django-cors-headers==2.1.0 django-environ==0.4.4 django-filter==1.1.0 djangorestframework==3.7.7