Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,34 @@
https://docs.djangoproject.com/en/6.0/ref/settings/
"""

import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/
# Settings are environment-driven so the same file works locally and in
# production. The defaults keep local development working out of the box.


def _env_list(name, default=''):
value = os.environ.get(name, default)
return [item.strip() for item in value.split(',') if item.strip()]


# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-hv7w)krtshfc5ag$#w+*@sx-@38japanbw$m$)f8#lp3t*9fbq'
SECRET_KEY = os.environ.get(
'DJANGO_SECRET_KEY',
'django-insecure-hv7w)krtshfc5ag$#w+*@sx-@38japanbw$m$)f8#lp3t*9fbq',
)

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = os.environ.get('DJANGO_DEBUG', 'True') == 'True'

ALLOWED_HOSTS = []
ALLOWED_HOSTS = _env_list('DJANGO_ALLOWED_HOSTS', 'localhost,127.0.0.1')

CSRF_TRUSTED_ORIGINS = _env_list('DJANGO_CSRF_TRUSTED_ORIGINS')


# Application definition
Expand All @@ -38,6 +50,7 @@
'django.contrib.messages',
'django.contrib.staticfiles',
# Third-party
'corsheaders',
'django_filters',
'rest_framework',
'rest_framework.authtoken',
Expand All @@ -51,6 +64,7 @@

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
Expand Down Expand Up @@ -98,6 +112,15 @@
}


# Cross-Origin Resource Sharing (django-cors-headers)
# Origins that are allowed to call the API from a browser.

CORS_ALLOWED_ORIGINS = _env_list(
'DJANGO_CORS_ALLOWED_ORIGINS',
'http://127.0.0.1:5500,http://localhost:5500',
)


# Database
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases

Expand Down Expand Up @@ -146,3 +169,13 @@
# https://docs.djangoproject.com/en/6.0/howto/static-files/

STATIC_URL = 'static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'


# Deployment behind a reverse proxy (Nginx/Cloudflare) that terminates HTTPS.

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

if not DEBUG:
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ asgiref==3.11.1
colorama==0.4.6
coverage==7.14.3
Django==6.0.6
django-cors-headers==4.9.0
django-filter==25.2
django-stubs==6.0.6
django-stubs-ext==6.0.6
Expand Down