Skip to content

Commit 4479296

Browse files
committed
adds cors
1 parent a08e1dc commit 4479296

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ DEBUG=True
55
SECRET_KEY=supersecretkey
66
DJANGO_SECRET_KEY=supersecretkey
77
ALLOWED_HOSTS=localhost,127.0.0.1
8+
CORS_ALLOWED_ORIGINS=http://localhost:8000,http://127.0.0.1:8000
89

910
# =============================================
1011
# БАЗА ДАННЫХ (PostgreSQL)

config/settings.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,31 @@
160160
# ====================
161161
# CORS SETTINGS
162162
# ====================
163-
CORS_ALLOWED_ORIGINS = [
164-
"http://localhost:5173", # Vite dev server
165-
"http://127.0.0.1:5173",
166-
"http://localhost:3000", # Alternative frontend port
167-
"http://127.0.0.1:3000",
168-
]
163+
# Настройки CORS (Cross-Origin Resource Sharing)
164+
CORS_ALLOWED_ORIGINS = env.list("CORS_ALLOWED_ORIGINS")
169165

166+
# Разрешить куки и заголовки авторизации
170167
CORS_ALLOW_CREDENTIALS = True
171168

172-
CORS_ALLOW_ALL_ORIGINS = DEBUG # Only allow all origins in development
169+
# Разрешенные методы (опционально, можно не указывать, так как по умолчанию разрешены безопасные методы)
170+
CORS_ALLOW_METHODS = [
171+
"DELETE",
172+
"GET",
173+
"OPTIONS",
174+
"PATCH",
175+
"POST",
176+
"PUT",
177+
]
178+
179+
# Разрешенные заголовки (опционально)
180+
CORS_ALLOW_HEADERS = [
181+
"accept",
182+
"accept-encoding",
183+
"authorization",
184+
"content-type",
185+
"dnt",
186+
"origin",
187+
"user-agent",
188+
"x-csrftoken",
189+
"x-requested-with",
190+
]

0 commit comments

Comments
 (0)