- Add dj-database-url package for parsing DATABASE_URL - Replace hardcoded PostgreSQL config with DATABASE_URL environment variable - Add connection pooling with conn_max_age and health checks - Fallback to SQLite for local development when DATABASE_URL is not set - Remove obsolete production config comments - Update requirements.txt with new dependency This change improves deployment flexibility by supporting standard DATABASE_URL format commonly used in cloud platforms (Heroku, Railway, etc.) while maintaining backward compatibility with local development using SQLite.
204 lines
5.0 KiB
Python
204 lines
5.0 KiB
Python
import os
|
|
from pathlib import Path
|
|
from datetime import timedelta
|
|
from dotenv import load_dotenv
|
|
import dj_database_url
|
|
|
|
load_dotenv()
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
|
|
SECRET_KEY = os.getenv('JWT_SECRET', 'django-insecure-fallback-secret-key')
|
|
|
|
DEBUG = os.getenv('DEBUG')
|
|
|
|
ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', '*').split(',')
|
|
|
|
CORS_ALLOWED_ORIGINS = os.getenv(
|
|
'CORS_ALLOWED_ORIGINS',
|
|
'http://localhost:3000,http://127.0.0.1:3000'
|
|
).split(',')
|
|
|
|
|
|
|
|
INSTALLED_APPS = [
|
|
'jazzmin',
|
|
'django.contrib.admin',
|
|
'django.contrib.auth',
|
|
'django.contrib.contenttypes',
|
|
'django.contrib.sessions',
|
|
'django.contrib.messages',
|
|
'django.contrib.staticfiles',
|
|
|
|
'rest_framework',
|
|
'rest_framework_simplejwt',
|
|
'corsheaders',
|
|
|
|
'users',
|
|
'meetings',
|
|
]
|
|
|
|
MIDDLEWARE = [
|
|
'corsheaders.middleware.CorsMiddleware',
|
|
'django.middleware.security.SecurityMiddleware',
|
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
|
'django.middleware.common.CommonMiddleware',
|
|
'django.middleware.csrf.CsrfViewMiddleware',
|
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
'django.contrib.messages.middleware.MessageMiddleware',
|
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
|
]
|
|
|
|
SITE_NAME = os.getenv('SITE_NAME', 'Attune Heart Therapy')
|
|
|
|
ROOT_URLCONF = 'booking_system.urls'
|
|
|
|
TEMPLATES = [
|
|
{
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
'DIRS': [
|
|
os.path.join(BASE_DIR, 'templates'),
|
|
],
|
|
'APP_DIRS': True,
|
|
'OPTIONS': {
|
|
'context_processors': [
|
|
'django.template.context_processors.request',
|
|
'django.contrib.auth.context_processors.auth',
|
|
'django.contrib.messages.context_processors.messages',
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
WSGI_APPLICATION = 'booking_system.wsgi.application'
|
|
|
|
if not DEBUG:
|
|
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
|
|
|
|
|
if os.getenv('DATABASE_URL'):
|
|
DATABASES = {
|
|
'default': dj_database_url.config(
|
|
default=os.getenv('DATABASE_URL'),
|
|
conn_max_age=600,
|
|
conn_health_checks=True,
|
|
)
|
|
}
|
|
else:
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.sqlite3',
|
|
'NAME': BASE_DIR / 'db.sqlite3',
|
|
}
|
|
}
|
|
|
|
ENCRYPTION_KEY = os.getenv('ENCRYPTION_KEY')
|
|
|
|
|
|
|
|
AUTH_PASSWORD_VALIDATORS = [
|
|
{
|
|
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
|
},
|
|
{
|
|
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
|
},
|
|
{
|
|
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
|
},
|
|
{
|
|
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
|
},
|
|
]
|
|
|
|
|
|
SIMPLE_JWT = {
|
|
'ACCESS_TOKEN_LIFETIME': timedelta(hours=24),
|
|
'REFRESH_TOKEN_LIFETIME': timedelta(days=7),
|
|
'ROTATE_REFRESH_TOKENS': True,
|
|
'BLACKLIST_AFTER_ROTATION': True,
|
|
'SIGNING_KEY': os.getenv('JWT_SECRET', SECRET_KEY),
|
|
'AUTH_HEADER_TYPES': ('Bearer',),
|
|
}
|
|
|
|
|
|
# Stripe Configuration
|
|
STRIPE_PUBLISHABLE_KEY = os.getenv('STRIPE_PUBLISHABLE_KEY')
|
|
STRIPE_SECRET_KEY = os.getenv('STRIPE_SECRET_KEY')
|
|
STRIPE_WEBHOOK_SECRET = os.getenv('STRIPE_WEBHOOK_SECRET')
|
|
|
|
|
|
# Jitsi Configuration
|
|
JITSI_BASE_URL = os.getenv('JITSI_BASE_URL', 'https://meet.jit.si')
|
|
|
|
# Email Configuration
|
|
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
|
EMAIL_HOST = os.getenv('SMTP_HOST', 'smtp.hostinger.com')
|
|
EMAIL_PORT = int(os.getenv('SMTP_PORT', 465))
|
|
EMAIL_USE_SSL = True
|
|
EMAIL_HOST_USER = os.getenv('SMTP_USERNAME', 'hello@attunehearttherapy.com')
|
|
EMAIL_HOST_PASSWORD = os.getenv('SMTP_PASSWORD', 'G&n2S;ffTc8f')
|
|
DEFAULT_FROM_EMAIL = os.getenv('SMTP_FROM', 'hello@attunehearttherapy.com')
|
|
|
|
|
|
REST_FRAMEWORK = {
|
|
'DEFAULT_AUTHENTICATION_CLASSES': (
|
|
'rest_framework_simplejwt.authentication.JWTAuthentication',
|
|
),
|
|
'DEFAULT_PERMISSION_CLASSES': (
|
|
'rest_framework.permissions.IsAuthenticated',
|
|
),
|
|
'DEFAULT_RENDERER_CLASSES': (
|
|
'rest_framework.renderers.JSONRenderer',
|
|
),
|
|
}
|
|
|
|
CORS_ALLOWED_ORIGINS = [
|
|
"http://localhost:3000",
|
|
"http://127.0.0.1:3000",
|
|
"http://localhost:8080",
|
|
"http://127.0.0.1:8080",
|
|
]
|
|
|
|
CORS_ALLOW_CREDENTIALS = True
|
|
|
|
|
|
|
|
ROOT_URLCONF = 'booking_system.urls'
|
|
|
|
AUTH_USER_MODEL = 'users.CustomUser'
|
|
|
|
AUTHENTICATION_BACKENDS = [
|
|
'users.backends.EmailBackend',
|
|
'django.contrib.auth.backends.ModelBackend',
|
|
]
|
|
|
|
|
|
LANGUAGE_CODE = 'en-us'
|
|
TIME_ZONE = 'UTC'
|
|
USE_I18N = True
|
|
USE_TZ = True
|
|
|
|
STATIC_URL = '/static/'
|
|
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
|
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
|
|
CELERY_BROKER_URL = 'redis://localhost:6379/0'
|
|
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
|
|
CELERY_ACCEPT_CONTENT = ['json']
|
|
CELERY_TASK_SERIALIZER = 'json'
|
|
|
|
LOGGING = {
|
|
'version': 1,
|
|
'disable_existing_loggers': False,
|
|
'handlers': {
|
|
'console': {
|
|
'class': 'logging.StreamHandler',
|
|
},
|
|
},
|
|
'root': {
|
|
'handlers': ['console'],
|
|
'level': 'INFO',
|
|
},
|
|
} |