163 lines
3.8 KiB
Python
163 lines
3.8 KiB
Python
import os
|
|
from pathlib import Path
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
|
|
SECRET_KEY = os.environ.get("SECRET_KEY")
|
|
if not SECRET_KEY:
|
|
raise ValueError("SECRET_KEY environment variable must be set")
|
|
|
|
DEBUG = os.environ.get("DEBUG", "True").lower() in ("true", "1", "yes")
|
|
|
|
ALLOWED_HOSTS = (
|
|
os.environ.get("ALLOWED_HOSTS", "").split(",")
|
|
if os.environ.get("ALLOWED_HOSTS")
|
|
else []
|
|
)
|
|
|
|
if DEBUG and not os.environ.get("ALLOWED_HOSTS"):
|
|
ALLOWED_HOSTS.extend(["localhost", "127.0.0.1", "django", "nginx"])
|
|
|
|
CSRF_TRUSTED_ORIGINS = (
|
|
os.environ.get("CSRF_TRUSTED_ORIGINS", "").split(",")
|
|
if os.environ.get("CSRF_TRUSTED_ORIGINS")
|
|
else []
|
|
)
|
|
NGINX_PORT = os.environ.get("NGINX_PORT", "8080")
|
|
|
|
for host in ALLOWED_HOSTS:
|
|
if host and host not in ["django", "nginx"]:
|
|
CSRF_TRUSTED_ORIGINS.extend(
|
|
[
|
|
f"http://{host}:{NGINX_PORT}",
|
|
f"https://{host}:{NGINX_PORT}",
|
|
f"http://{host}",
|
|
f"https://{host}",
|
|
]
|
|
)
|
|
|
|
USE_X_FORWARDED_HOST = True
|
|
USE_X_FORWARDED_PORT = True
|
|
|
|
INSTALLED_APPS = [
|
|
"daphne",
|
|
"django.contrib.admin",
|
|
"django.contrib.auth",
|
|
"django.contrib.contenttypes",
|
|
"django.contrib.sessions",
|
|
"django.contrib.messages",
|
|
"django.contrib.staticfiles",
|
|
# Third party
|
|
"channels",
|
|
"liveview",
|
|
# Kakebo apps
|
|
"app.public.apps.PublicConfig",
|
|
"app.expenses.apps.ExpensesConfig",
|
|
"app.monthly.apps.MonthlyConfig",
|
|
"app.yearly.apps.YearlyConfig",
|
|
# Vite
|
|
"django_vite",
|
|
# API
|
|
"rest_framework",
|
|
"app.api.apps.ApiConfig",
|
|
]
|
|
|
|
MIDDLEWARE = [
|
|
"django.middleware.security.SecurityMiddleware",
|
|
"whitenoise.middleware.WhiteNoiseMiddleware",
|
|
"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",
|
|
]
|
|
|
|
ROOT_URLCONF = "core.urls"
|
|
|
|
TEMPLATES = [
|
|
{
|
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
"DIRS": [BASE_DIR / "templates"],
|
|
"APP_DIRS": True,
|
|
"OPTIONS": {
|
|
"context_processors": [
|
|
"django.template.context_processors.debug",
|
|
"django.template.context_processors.request",
|
|
"django.contrib.auth.context_processors.auth",
|
|
"django.contrib.messages.context_processors.messages",
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
WSGI_APPLICATION = "core.wsgi.application"
|
|
ASGI_APPLICATION = "core.asgi.application"
|
|
|
|
DATABASES = {
|
|
"default": {
|
|
"ENGINE": "django.db.backends.sqlite3",
|
|
"NAME": BASE_DIR / "db.sqlite3",
|
|
}
|
|
}
|
|
|
|
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"},
|
|
]
|
|
|
|
LANGUAGE_CODE = "en-us"
|
|
TIME_ZONE = "Europe/Madrid"
|
|
USE_I18N = True
|
|
USE_TZ = True
|
|
|
|
STATIC_URL = "/static/"
|
|
STATIC_ROOT = BASE_DIR / "staticfiles"
|
|
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
|
|
|
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
|
|
|
LOGIN_URL = "/login/"
|
|
LOGIN_REDIRECT_URL = "/"
|
|
LOGOUT_REDIRECT_URL = "/login/"
|
|
|
|
# Django Channels
|
|
CHANNEL_LAYERS = {
|
|
"default": {
|
|
"BACKEND": "channels_redis.core.RedisChannelLayer",
|
|
"CONFIG": {
|
|
"hosts": [
|
|
(
|
|
os.environ.get("REDIS_HOST", "redis"),
|
|
int(os.environ.get("REDIS_PORT", 6379)),
|
|
)
|
|
],
|
|
},
|
|
},
|
|
}
|
|
|
|
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
|
|
|
# Django Vite
|
|
DJANGO_VITE = {
|
|
"default": {
|
|
"dev_mode": False,
|
|
"manifest_path": BASE_DIR / "static" / ".vite" / "manifest.json",
|
|
}
|
|
}
|
|
|
|
# Django REST Framework
|
|
REST_FRAMEWORK = {
|
|
"DEFAULT_AUTHENTICATION_CLASSES": [],
|
|
"DEFAULT_PERMISSION_CLASSES": [
|
|
"rest_framework.permissions.IsAuthenticated",
|
|
],
|
|
"DEFAULT_RENDERER_CLASSES": [
|
|
"rest_framework.renderers.JSONRenderer",
|
|
],
|
|
}
|