diff --git a/Pipfile b/Pipfile index 1e862b0..6637603 100644 --- a/Pipfile +++ b/Pipfile @@ -14,6 +14,7 @@ dj-database-url = "*" python-dotenv = "*" gunicorn = "*" whitenoise = "*" +django-cors-headers = "*" [requires] python_version = "3.8" diff --git a/Pipfile.lock b/Pipfile.lock index 2ef0291..a7fe798 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "a25ca89be3f4cece40a21706dbfcbe4881c85256c7952735821d2ff0b3feac6f" + "sha256": "cc2b2c810cbcf08a8b06bcbbf072d05f88e6c769541d4610cd23c8b0effb8565" }, "pipfile-spec": 6, "requires": { @@ -40,6 +40,14 @@ "index": "pypi", "version": "==3.1.2" }, + "django-cors-headers": { + "hashes": [ + "sha256:9322255c296d5f75089571f29e520c83ff9693df17aa3cf9f6a4bea7c6740169", + "sha256:db82b2840f667d47872ae3e4a4e0a0d72fbecb42779b8aa233fa8bb965f7836a" + ], + "index": "pypi", + "version": "==3.5.0" + }, "django-extensions": { "hashes": [ "sha256:6809c89ca952f0e08d4e0766bc0101dfaf508d7649aced1180c091d737046ea7", diff --git a/django_rest_api/settings.py b/django_rest_api/settings.py index 349e065..fe27b55 100644 --- a/django_rest_api/settings.py +++ b/django_rest_api/settings.py @@ -42,11 +42,13 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'django_extensions', + 'corsheaders', 'rest_framework', 'contacts_api', ] MIDDLEWARE = [ + 'corsheaders.middleware.CorsMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -57,6 +59,10 @@ MIDDLEWARE = [ 'whitenoise.middleware.WhiteNoiseMiddleware', ] +# Configure cors to whitelist all origins +# https://github.com/adamchainz/django-cors-headers#cors_allow_all_origins +CORS_ALLOW_ALL_ORIGINS = True + # Simplified static file serving. # https://warehouse.python.org/project/whitenoise/ STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'