Skip to content

Commit 7e3ca98

Browse files
committed
cors issue
1 parent 68ed9b0 commit 7e3ca98

1 file changed

Lines changed: 18 additions & 43 deletions

File tree

backend/core/settings.py

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
"""
22
Django settings for core project.
3-
4-
Generated by 'django-admin startproject' using Django 6.0.2.
5-
6-
For more information on this file, see
7-
https://docs.djangoproject.com/en/6.0/topics/settings/
8-
9-
For the full list of settings and their values, see
10-
https://docs.djangoproject.com/en/6.0/ref/settings/
113
"""
124

135
from pathlib import Path
@@ -19,10 +11,6 @@
1911
# Build paths inside the project like this: BASE_DIR / 'subdir'.
2012
BASE_DIR = Path(__file__).resolve().parent.parent
2113

22-
23-
# Quick-start development settings - unsuitable for production
24-
# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/
25-
2614
# SECURITY WARNING: keep the secret key used in production secret!
2715
SECRET_KEY = os.getenv('SECRET_KEY', 'django-insecure-4!)sv6=xv!rd-%py*h**vhrm)m(%-_2^j()bs&j9uj2u8!fkv6')
2816

@@ -31,9 +19,7 @@
3119

3220
ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', '').split(',') if os.getenv('ALLOWED_HOSTS') else ['*']
3321

34-
3522
# Application definition
36-
3723
INSTALLED_APPS = [
3824
'django.contrib.admin',
3925
'django.contrib.auth',
@@ -49,7 +35,7 @@
4935
]
5036

5137
MIDDLEWARE = [
52-
'corsheaders.middleware.CorsMiddleware',
38+
'corsheaders.middleware.CorsMiddleware', # Preflight and CORS must be FIRST
5339
'django.middleware.security.SecurityMiddleware',
5440
'whitenoise.middleware.WhiteNoiseMiddleware',
5541
'django.contrib.sessions.middleware.SessionMiddleware',
@@ -61,6 +47,9 @@
6147
]
6248

6349
ROOT_URLCONF = 'core.urls'
50+
51+
# IMPORTANT: User requested no trailing slashes.
52+
# Disabling APPEND_SLASH prevents Django from automatically redirecting to / versions.
6453
APPEND_SLASH = False
6554

6655
TEMPLATES = [
@@ -80,60 +69,46 @@
8069

8170
WSGI_APPLICATION = 'core.wsgi.application'
8271

83-
8472
# Database
85-
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases
86-
8773
DATABASES = {}
8874

89-
# CORS settings
75+
# CORS settings - Bulletproof for Netlify migration
9076
CORS_ALLOW_ALL_ORIGINS = True
77+
CORS_ORIGIN_ALLOW_ALL = True # Legacy compatibility
9178
CORS_ALLOW_CREDENTIALS = True
92-
# Fallback for strict environments (Netlify + Vercel)
79+
80+
# Explicitly Trusting modern origins to prevent browser-side rejections
9381
CORS_ALLOWED_ORIGINS = [
9482
"https://hrms-lite-frontend.vercel.app",
9583
"https://hrms-lite-version.netlify.app",
9684
]
85+
9786
CORS_ALLOWED_ORIGIN_REGEXES = [
9887
r"^https://.*\.netlify\.app$",
9988
r"^https://.*\.vercel\.app$",
10089
]
10190

91+
# CSRF security for POST requests from cross-origin domains
92+
CSRF_TRUSTED_ORIGINS = [
93+
"https://hrms-lite-frontend.vercel.app",
94+
"https://hrms-lite-version.netlify.app",
95+
]
10296

10397
# Password validation
104-
# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators
105-
10698
AUTH_PASSWORD_VALIDATORS = [
107-
{
108-
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
109-
},
110-
{
111-
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
112-
},
113-
{
114-
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
115-
},
116-
{
117-
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
118-
},
99+
{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'},
100+
{'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator'},
101+
{'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator'},
102+
{'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator'},
119103
]
120104

121-
122105
# Internationalization
123-
# https://docs.djangoproject.com/en/6.0/topics/i18n/
124-
125106
LANGUAGE_CODE = 'en-us'
126-
127107
TIME_ZONE = 'UTC'
128-
129108
USE_I18N = True
130-
131109
USE_TZ = True
132110

133-
134111
# Static files (CSS, JavaScript, Images)
135-
# https://docs.djangoproject.com/en/6.0/howto/static-files/
136-
137112
STATIC_URL = '/static/'
138113
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
139114
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

0 commit comments

Comments
 (0)