| import os |
| from pathlib import Path |
| from urllib.parse import unquote, urlparse |
|
|
| from dotenv import load_dotenv |
|
|
|
|
| BASE_DIR = Path(__file__).resolve().parent.parent |
| load_dotenv(BASE_DIR / ".env") |
|
|
| SECRET_KEY = os.environ.get("SECRET_KEY", "django-insecure-flux-local-key") |
| DEBUG = os.environ.get("DEBUG", "True").lower() in ("1", "true", "yes", "on") |
| ALLOWED_HOSTS = [ |
| host.strip() |
| for host in os.environ.get("ALLOWED_HOSTS", "localhost,127.0.0.1").split(",") |
| if host.strip() |
| ] |
|
|
| if DEBUG and "*" not in ALLOWED_HOSTS: |
| ALLOWED_HOSTS.append("*") |
|
|
| INSTALLED_APPS = [ |
| "daphne", |
| "django.contrib.auth", |
| "django.contrib.contenttypes", |
| "django.contrib.sessions", |
| "django.contrib.staticfiles", |
| "corsheaders", |
| "rest_framework", |
| "channels", |
| "apps.accounts", |
| "apps.calls", |
| ] |
|
|
| MIDDLEWARE = [ |
| "corsheaders.middleware.CorsMiddleware", |
| "django.middleware.security.SecurityMiddleware", |
| "django.contrib.sessions.middleware.SessionMiddleware", |
| "django.middleware.common.CommonMiddleware", |
| ] |
|
|
| ROOT_URLCONF = "flux_backend.urls" |
| ASGI_APPLICATION = "flux_backend.asgi.application" |
| WSGI_APPLICATION = "flux_backend.wsgi.application" |
|
|
| DATABASE_URL = os.environ.get("DATABASE_URL", "").strip() |
| if DATABASE_URL: |
| parsed_db = urlparse(DATABASE_URL) |
| DATABASES = { |
| "default": { |
| "ENGINE": "django.db.backends.postgresql", |
| "NAME": parsed_db.path.lstrip("/"), |
| "USER": unquote(parsed_db.username or ""), |
| "PASSWORD": unquote(parsed_db.password or ""), |
| "HOST": parsed_db.hostname, |
| "PORT": parsed_db.port or 5432, |
| "OPTIONS": {"sslmode": "require"}, |
| } |
| } |
| else: |
| DATABASES = { |
| "default": { |
| "ENGINE": "django.db.backends.sqlite3", |
| "NAME": BASE_DIR / "db.sqlite3", |
| } |
| } |
|
|
| REST_FRAMEWORK = { |
| "DEFAULT_PERMISSION_CLASSES": [ |
| "rest_framework.permissions.AllowAny", |
| ], |
| } |
|
|
| FRONTEND_URL = os.environ.get("FRONTEND_URL", "http://localhost:3000") |
| CORS_ALLOW_ALL_ORIGINS = os.environ.get("CORS_ALLOW_ALL_ORIGINS", "True").lower() in ("1", "true", "yes", "on") |
| CORS_ALLOW_CREDENTIALS = True |
| CORS_ALLOWED_ORIGINS = [ |
| origin.strip() |
| for origin in os.environ.get("CORS_ALLOWED_ORIGINS", FRONTEND_URL).split(",") |
| if origin.strip() |
| ] |
|
|
| CHANNEL_LAYERS = { |
| "default": { |
| "BACKEND": "channels.layers.InMemoryChannelLayer", |
| }, |
| } |
|
|
| LANGUAGE_CODE = "en-us" |
| TIME_ZONE = "UTC" |
| USE_I18N = True |
| USE_TZ = True |
| STATIC_URL = "static/" |
| DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" |
|
|
| GOOGLE_CLIENT_ID = os.environ.get("GOOGLE_CLIENT_ID", "") |
| SUPABASE_URL = os.environ.get("SUPABASE_URL", "") |
| SUPABASE_ANON_KEY = os.environ.get("SUPABASE_ANON_KEY", "") |
|
|