diff --git a/.env.example b/.env.example index 99b2bd5..c3756ec 100644 --- a/.env.example +++ b/.env.example @@ -5,6 +5,7 @@ DEBUG=True SECRET_KEY=supersecretkey DJANGO_SECRET_KEY=supersecretkey ALLOWED_HOSTS=localhost,127.0.0.1 +CORS_ALLOWED_ORIGINS=http://localhost:8000,http://127.0.0.1:8000 # ============================================= # БАЗА ДАННЫХ (PostgreSQL) diff --git a/config/settings.py b/config/settings.py index 4c46059..ff5aae7 100644 --- a/config/settings.py +++ b/config/settings.py @@ -160,13 +160,31 @@ # ==================== # CORS SETTINGS # ==================== -CORS_ALLOWED_ORIGINS = [ - "http://localhost:5173", # Vite dev server - "http://127.0.0.1:5173", - "http://localhost:3000", # Alternative frontend port - "http://127.0.0.1:3000", -] +# Настройки CORS (Cross-Origin Resource Sharing) +CORS_ALLOWED_ORIGINS = env.list("CORS_ALLOWED_ORIGINS") +# Разрешить куки и заголовки авторизации CORS_ALLOW_CREDENTIALS = True -CORS_ALLOW_ALL_ORIGINS = DEBUG # Only allow all origins in development +# Разрешенные методы (опционально, можно не указывать, так как по умолчанию разрешены безопасные методы) +CORS_ALLOW_METHODS = [ + "DELETE", + "GET", + "OPTIONS", + "PATCH", + "POST", + "PUT", +] + +# Разрешенные заголовки (опционально) +CORS_ALLOW_HEADERS = [ + "accept", + "accept-encoding", + "authorization", + "content-type", + "dnt", + "origin", + "user-agent", + "x-csrftoken", + "x-requested-with", +]