|
|
|
@ -25,7 +25,7 @@ load_dotenv(BASE_DIR.parent / '.env') |
|
|
|
# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/ |
|
|
|
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret! |
|
|
|
SECRET_KEY = os.getenv('DJANGO_SECRET_KEY', 'django-insecure-@8*97xo5!gdi!x*94-%n8$b63%ljy#@&^#7$h!9v-4a2#r+98t') |
|
|
|
SECRET_KEY = os.getenv('DJANGO_SECRET_KEY') |
|
|
|
|
|
|
|
# Environment setup (development / production) |
|
|
|
# Reads DEV=True for development, DEV=False for production |
|
|
|
@ -41,15 +41,22 @@ if IS_DEV: |
|
|
|
] |
|
|
|
else: |
|
|
|
DEBUG = os.getenv('DJANGO_DEBUG', 'False').lower() in ('true', '1', 't') |
|
|
|
allowed_hosts_raw = os.getenv('ALLOWED_HOSTS', '*') |
|
|
|
allowed_hosts_raw = os.getenv('ALLOWED_HOSTS', '') |
|
|
|
ALLOWED_HOSTS = [host.strip() for host in allowed_hosts_raw.split(',') if host.strip()] |
|
|
|
if '*' not in ALLOWED_HOSTS: |
|
|
|
ALLOWED_HOSTS.append('*') |
|
|
|
|
|
|
|
CORS_ALLOW_ALL_ORIGINS = True |
|
|
|
csrf_origins = os.getenv('CSRF_TRUSTED_ORIGINS', 'https://divar.nwhco.ir,http://divar.nwhco.ir,http://localhost,http://127.0.0.1') |
|
|
|
CORS_ALLOW_ALL_ORIGINS = os.getenv('CORS_ALLOW_ALL_ORIGINS', 'False').lower() in ('true', '1', 't') |
|
|
|
if not CORS_ALLOW_ALL_ORIGINS: |
|
|
|
cors_allowed = os.getenv('CORS_ALLOWED_ORIGINS', '') |
|
|
|
CORS_ALLOWED_ORIGINS = [origin.strip() for origin in cors_allowed.split(',') if origin.strip()] |
|
|
|
|
|
|
|
csrf_origins = os.getenv('CSRF_TRUSTED_ORIGINS', '') |
|
|
|
CSRF_TRUSTED_ORIGINS = [origin.strip() for origin in csrf_origins.split(',') if origin.strip()] |
|
|
|
|
|
|
|
# Security Headers for production |
|
|
|
SECURE_BROWSER_XSS_FILTER = True |
|
|
|
SECURE_CONTENT_TYPE_NOSNIFF = True |
|
|
|
X_FRAME_OPTIONS = 'DENY' |
|
|
|
|
|
|
|
# Reverse Proxy SSL / Host headers configuration (for Nginx / Docker reverse proxies) |
|
|
|
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') |
|
|
|
USE_X_FORWARDED_HOST = True |
|
|
|
@ -190,14 +197,6 @@ STORAGES = { |
|
|
|
# https://docs.djangoproject.com/en/6.0/ref/settings/#default-auto-field |
|
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' |
|
|
|
|
|
|
|
# CORS & CSRF Settings |
|
|
|
CORS_ALLOW_ALL_ORIGINS = os.getenv('CORS_ALLOW_ALL_ORIGINS', 'True').lower() in ('true', '1', 't') |
|
|
|
if not CORS_ALLOW_ALL_ORIGINS: |
|
|
|
CORS_ALLOWED_ORIGINS = [origin.strip() for origin in os.getenv('CORS_ALLOWED_ORIGINS', '').split(',') if origin.strip()] |
|
|
|
|
|
|
|
csrf_origins = os.getenv('CSRF_TRUSTED_ORIGINS', 'http://localhost,http://127.0.0.1,http://localhost:5173,http://localhost:8000') |
|
|
|
CSRF_TRUSTED_ORIGINS = [origin.strip() for origin in csrf_origins.split(',') if origin.strip()] |
|
|
|
|
|
|
|
# Django REST Framework Settings |
|
|
|
REST_FRAMEWORK = { |
|
|
|
'DEFAULT_PERMISSION_CLASSES': [ |
|
|
|
|