Skip to content

Commit

Permalink
Merge pull request #177 from CogitoNTNU/development
Browse files Browse the repository at this point in the history
build: Update DEBUG setting in settings.py and docker-compose.yml and…
  • Loading branch information
SverreNystad authored Sep 5, 2024
2 parents a62ad5d + 0b8d5f1 commit 6a4a19b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
- name: Build docker image and run tests
env:
DJANGO_SECRET_KEY: ${{ secrets.DJANGO_SECRET_KEY }}
DEBUG: "True"
run: |
docker compose build
docker compose run cogito python manage.py makemigrations
Expand Down
18 changes: 16 additions & 2 deletions cogito/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
SECRET_KEY = os.getenv("DJANGO_SECRET_KEY")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv("DEBUG", False)
DEBUG = os.getenv("DEBUG", "False") == "True"

ALLOWED_HOSTS = [
"backend.cogito-ntnu.no",
Expand Down Expand Up @@ -89,7 +89,21 @@
},
]

WSGI_APPLICATION = "cogito.wsgi.application"
# HTTPS settings applied only in production
if not DEBUG:
print("Running in production mode", flush=True)
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
SECURE_SSL_REDIRECT = True
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True
else:
# Development-only settings
# Disable secure headers and redirections
print("Running in development mode", flush=True)
SECURE_PROXY_SSL_HEADER = None
SECURE_SSL_REDIRECT = False
CSRF_COOKIE_SECURE = False
SESSION_COOKIE_SECURE = False

# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
depends_on:
- db
environment:
- DEBUG=True
- DEBUG
- EMAIL_HOST_USER
- EMAIL_HOST_PASSWORD
- DJANGO_SECRET_KEY
Expand Down

0 comments on commit 6a4a19b

Please sign in to comment.