Skip to content

Commit

Permalink
[FEAT] only enable cors middleware if DJANGO_CORS_ALLOWED_ORIGINS is set
Browse files Browse the repository at this point in the history
  • Loading branch information
dameyerdave committed Jan 4, 2024
1 parent 78866e8 commit 83a52e2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions api/app/ena_upload_ms/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"corsheaders.middleware.CorsMiddleware",
]

# We only add the middleware if DJANGO_CORS_ALLOWED_ORIGINS env var is set
if environ.get("DJANGO_CORS_ALLOWED_ORIGINS"):
MIDDLEWARE.append(
"corsheaders.middleware.CorsMiddleware",
)

MIDDLEWARE += [
"django.middleware.common.CommonMiddleware",
]

Expand Down Expand Up @@ -190,7 +198,7 @@

# CORS configuration
CORS_ALLOW_ALL_ORIGINS = False if environ.get("DJANGO_CORS_ALLOWED_ORIGINS") else True
CORS_ALLOWED_ORIGINS = environ.get("DJANGO_CORS_ALLOWED_ORIGINS" "*").split(",")
CORS_ALLOWED_ORIGINS = environ.get("DJANGO_CORS_ALLOWED_ORIGINS", "*").split(",")
CORS_ALLOW_HEADERS = default_headers + (
"cache-control",
"pragma",
Expand Down

0 comments on commit 83a52e2

Please sign in to comment.