rinogeek commited on
Commit
7cfcf72
·
1 Parent(s): baf9516

Add CORS and CSRF configuration for frontend-backend connection

Browse files
Files changed (2) hide show
  1. .env.production +3 -0
  2. educonnect/settings.py +16 -0
.env.production CHANGED
@@ -10,6 +10,9 @@ ALLOWED_HOSTS=localhost,127.0.0.1,.hf.space
10
  # CORS - Autoriser le frontend Hugging Face
11
  CORS_ALLOWED_ORIGINS=https://rinogeek-edulabfrontend.hf.space
12
 
 
 
 
13
  # Database - SQLite par défaut (pas de DB_HOST = utilise SQLite)
14
  # Pour PostgreSQL, décommentez et configurez :
15
  # DB_NAME=educonnect_db
 
10
  # CORS - Autoriser le frontend Hugging Face
11
  CORS_ALLOWED_ORIGINS=https://rinogeek-edulabfrontend.hf.space
12
 
13
+ # CSRF - Autoriser les origines de confiance
14
+ CSRF_TRUSTED_ORIGINS=https://rinogeek-edulabfrontend.hf.space,https://rinogeek-edulabbackend.hf.space
15
+
16
  # Database - SQLite par défaut (pas de DB_HOST = utilise SQLite)
17
  # Pour PostgreSQL, décommentez et configurez :
18
  # DB_NAME=educonnect_db
educonnect/settings.py CHANGED
@@ -185,6 +185,14 @@ CORS_ALLOWED_ORIGINS = config(
185
  default='http://localhost:3000,http://localhost:5173,http://localhost:3001,https://rinogeek-edulabfrontend.hf.space'
186
  ).split(',')
187
  CORS_ALLOW_CREDENTIALS = True
 
 
 
 
 
 
 
 
188
  CORS_ALLOW_HEADERS = [
189
  'accept',
190
  'accept-encoding',
@@ -196,6 +204,14 @@ CORS_ALLOW_HEADERS = [
196
  'x-csrftoken',
197
  'x-requested-with',
198
  ]
 
 
 
 
 
 
 
 
199
 
200
  # Channels Configuration (WebSockets)
201
  CHANNEL_LAYERS = {
 
185
  default='http://localhost:3000,http://localhost:5173,http://localhost:3001,https://rinogeek-edulabfrontend.hf.space'
186
  ).split(',')
187
  CORS_ALLOW_CREDENTIALS = True
188
+ CORS_ALLOW_METHODS = [
189
+ 'DELETE',
190
+ 'GET',
191
+ 'OPTIONS',
192
+ 'PATCH',
193
+ 'POST',
194
+ 'PUT',
195
+ ]
196
  CORS_ALLOW_HEADERS = [
197
  'accept',
198
  'accept-encoding',
 
204
  'x-csrftoken',
205
  'x-requested-with',
206
  ]
207
+ # Allow preflight requests to be cached
208
+ CORS_PREFLIGHT_MAX_AGE = 86400
209
+
210
+ # CSRF Configuration - Trust frontend origins
211
+ CSRF_TRUSTED_ORIGINS = config(
212
+ 'CSRF_TRUSTED_ORIGINS',
213
+ default='http://localhost:3000,http://localhost:5173,https://rinogeek-edulabfrontend.hf.space,https://rinogeek-edulabbackend.hf.space'
214
+ ).split(',')
215
 
216
  # Channels Configuration (WebSockets)
217
  CHANNEL_LAYERS = {