from .base import * import dj_database_url import os DEBUG = False # Comma-separated list of allowed hosts _allowed = os.getenv("ALLOWED_HOSTS", "") ALLOWED_HOSTS = [h.strip() for h in _allowed.split(",") if h.strip()] # Strict CORS _cors = os.getenv("CORS_ALLOWED_ORIGINS", "") CORS_ALLOWED_ORIGINS = [h.strip() for h in _cors.split(",") if h.strip()] CORS_ALLOW_ALL_ORIGINS = False # Production Database with Connection Pooling Settings DATABASES = { "default": { "ENGINE": "django.db.backends.mysql", "NAME": os.getenv("DB_NAME", "mtcbd_db"), "USER": os.getenv("DB_USER", "root"), "PASSWORD": os.getenv("DB_PASSWORD", ""), "HOST": os.getenv("DB_HOST", "127.0.0.1"), "PORT": os.getenv("DB_PORT", "3306"), "OPTIONS": { "init_command": "SET sql_mode='STRICT_TRANS_TABLES'", "charset": "utf8mb4", }, "CONN_MAX_AGE": int(os.getenv("DB_CONN_MAX_AGE", "60")), } } # Production security settings SECURE_SSL_REDIRECT = os.getenv("SECURE_SSL_REDIRECT", "True") == "True" SESSION_COOKIE_SECURE = True CSRF_COOKIE_SECURE = True SECURE_BROWSER_XSS_FILTER = True SECURE_CONTENT_TYPE_NOSNIFF = True # Redis caching CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", "LOCATION": os.getenv("REDIS_URL", "redis://127.0.0.1:6379/1"), "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", } } } # Production Logging LOGGING = { "version": 1, "disable_existing_loggers": False, "formatters": { "verbose": { "format": "{levelname} {asctime} {module} {process:d} {thread:d} {message}", "style": "{", }, }, "handlers": { "console": { "level": "INFO", "class": "logging.StreamHandler", "formatter": "verbose", }, }, "root": { "handlers": ["console"], "level": "INFO", }, "loggers": { "django": { "handlers": ["console"], "level": os.getenv("DJANGO_LOG_LEVEL", "INFO"), "propagate": False, }, }, }