Skip to content

Add production-ready settings and CORS configuration - #37

Merged
FriggemannMichael merged 1 commit into
mainfrom
feat/deploy-config
Jul 7, 2026
Merged

Add production-ready settings and CORS configuration#37
FriggemannMichael merged 1 commit into
mainfrom
feat/deploy-config

Conversation

@FriggemannMichael

Copy link
Copy Markdown
Owner

Prepares the backend for deployment (portfolio: coderr.friggemann.eu) without changing local behaviour.

What

  • Deployment-relevant settings are now read from DJANGO_* environment variables, with defaults that keep local dev identical:
    • DJANGO_SECRET_KEY, DJANGO_DEBUG, DJANGO_ALLOWED_HOSTS, DJANGO_CSRF_TRUSTED_ORIGINS, DJANGO_CORS_ALLOWED_ORIGINS.
  • Adds django-cors-headers (app + middleware) so the browser frontend can call the API cross-origin. Default allows the local Live Server origin (http://127.0.0.1:5500, http://localhost:5500).
  • Adds STATIC_ROOT (for collectstatic) and SECURE_PROXY_SSL_HEADER (HTTPS behind Nginx/Cloudflare); secure cookies when DEBUG is off.

Production environment variables (set on the server)

DJANGO_SECRET_KEY=<a fresh 50+ char random key>
DJANGO_DEBUG=False
DJANGO_ALLOWED_HOSTS=coderr.friggemann.eu
DJANGO_CSRF_TRUSTED_ORIGINS=https://coderr.friggemann.eu
DJANGO_CORS_ALLOWED_ORIGINS=https://michael-friggemann.developerakademie.net

Verification (local, CI-equivalent)

  • pytest153 passed, coverage 98.6%
  • ruff check . / ruff format . --check
  • DJANGO_DEBUG=False manage.py check (with prod env vars) → no issues

Make the deployment-relevant settings environment-driven so the same settings
file works locally and in production, with defaults that keep local development
unchanged:

- SECRET_KEY, DEBUG, ALLOWED_HOSTS, CSRF_TRUSTED_ORIGINS and CORS_ALLOWED_ORIGINS
  read from DJANGO_* environment variables.
- Add django-cors-headers (corsheaders app + middleware) so the browser frontend
  can call the API cross-origin; default allows the local Live Server origin.
- Add STATIC_ROOT for collectstatic and SECURE_PROXY_SSL_HEADER for running
  behind an HTTPS-terminating reverse proxy; enable secure cookies when DEBUG is
  off.
@FriggemannMichael
FriggemannMichael merged commit 208e38f into main Jul 7, 2026
1 check passed
@FriggemannMichael
FriggemannMichael deleted the feat/deploy-config branch July 7, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant