Skip to content

Commit 02081fb

Browse files
authored
Add support for CORS with Django (#2090)
* Add support for CORS with Django * Update settings.py per https://pypi.org/project/django-cors-headers/
1 parent f9747a0 commit 02081fb

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

pygeoapi/django_/settings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,10 @@
175175
# Defaults to True in Django
176176
# https://docs.djangoproject.com/en/3.2/ref/settings/#append-slash
177177
APPEND_SLASH = not API_RULES.strict_slashes
178+
179+
# CORS: optionally enable from config.
180+
if PYGEOAPI_CONFIG['server'].get('cors', False):
181+
INSTALLED_APPS.append('corsheaders')
182+
MIDDLEWARE.insert(0, 'corsheaders.middleware.CorsMiddleware')
183+
184+
CORS_ORIGIN_ALLOW_ALL = True

requirements-django.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Django
2+
django-cors-headers
23
pydantic

0 commit comments

Comments
 (0)