diff --git a/backend/berkeleytime/settings.py b/backend/berkeleytime/settings.py index dd6b97cd2..04604005d 100644 --- a/backend/berkeleytime/settings.py +++ b/backend/berkeleytime/settings.py @@ -92,6 +92,7 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'corsheaders', 'berkeleytime', 'catalog', 'enrollment', @@ -105,6 +106,9 @@ # Middlewares MIDDLEWARE = [ + # corsheaders middleware needs to go above everything else if possible + 'corsheaders.middleware.CorsMiddleware', + 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -120,6 +124,11 @@ # WSGI app object to use with runserver WSGI_APPLICATION = 'berkeleytime.wsgi.application' +# CORS configs +CORS_ALLOWED_ORIGIN_REGEXES = [ + r'^http\:\/\/(?:localhost|127\.0\.0\.1)\:\d+$' +] + # https://stackoverflow.com/questions/14058453/making-python-loggers-output-all-messages-to-stdout-in-addition-to-log-file import logging diff --git a/backend/requirements.txt b/backend/requirements.txt index 39b115950..940ae4fb3 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -23,3 +23,4 @@ python-dateutil==2.8.1 pyyaml==5.3.1 redlock-py==1.0.8 retry==0.9.2 +django-cors-headers==3.11.0