Add production-ready settings and CORS configuration - #37
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prepares the backend for deployment (portfolio: coderr.friggemann.eu) without changing local behaviour.
What
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.http://127.0.0.1:5500,http://localhost:5500).STATIC_ROOT(forcollectstatic) andSECURE_PROXY_SSL_HEADER(HTTPS behind Nginx/Cloudflare); secure cookies whenDEBUGis off.Production environment variables (set on the server)
Verification (local, CI-equivalent)
pytest→ 153 passed, coverage 98.6%ruff check ./ruff format . --check✅DJANGO_DEBUG=False manage.py check(with prod env vars) → no issues