fix(settings): accept JSON-array env lists in env_list
The production .env stores DJANGO_ALLOWED_HOSTS as a JSON array (legacy format), but env_list only split on commas, yielding broken entries like '["aimloperations.com"' and causing DisallowedHost (HTTP 400) for every request. Parse JSON arrays as well as comma-separated values. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
"""Shared Django settings for all environments."""
|
"""Shared Django settings for all environments."""
|
||||||
|
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
@@ -22,6 +23,15 @@ def env_list(key: str, default: str = "") -> list[str]:
|
|||||||
value = os.environ.get(key, default)
|
value = os.environ.get(key, default)
|
||||||
if not value:
|
if not value:
|
||||||
return []
|
return []
|
||||||
|
value = value.strip()
|
||||||
|
# Accept a JSON array (e.g. '["a","b"]') as well as a comma-separated list.
|
||||||
|
if value.startswith("["):
|
||||||
|
try:
|
||||||
|
parsed = json.loads(value)
|
||||||
|
except ValueError:
|
||||||
|
parsed = None
|
||||||
|
if isinstance(parsed, list):
|
||||||
|
return [str(item).strip() for item in parsed if str(item).strip()]
|
||||||
return [item.strip() for item in value.split(",") if item.strip()]
|
return [item.strip() for item in value.split(",") if item.strip()]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user