From 4dc6e9ee5b42d888a17c99fd9d1558e1e4e468c8 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Fri, 6 Sep 2024 19:58:17 +0800 Subject: [PATCH] Exclude silk middleware on production --- backend/config/settings.py | 70 ++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/backend/config/settings.py b/backend/config/settings.py index 514e5b1..d9de5e0 100644 --- a/backend/config/settings.py +++ b/backend/config/settings.py @@ -115,18 +115,47 @@ INSTALLED_APPS = [ 'notifications' ] -MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - "whitenoise.middleware.WhiteNoiseMiddleware", - "silk.middleware.SilkyMiddleware", - "django.contrib.sessions.middleware.SessionMiddleware", - "corsheaders.middleware.CorsMiddleware", - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', -] +if DEBUG: + MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + "whitenoise.middleware.WhiteNoiseMiddleware", + "silk.middleware.SilkyMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "corsheaders.middleware.CorsMiddleware", + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', + ] + DJANGO_LOG_LEVEL = "DEBUG" + # Enables VS Code debugger to break on raised exceptions + DEBUG_PROPAGATE_EXCEPTIONS = "DEBUG" + LOGGING = { + "version": 1, + "disable_existing_loggers": False, + "handlers": { + "console": { + "class": "logging.StreamHandler", + }, + }, + "root": { + "handlers": ["console"], + "level": "DEBUG", + }, + } +else: + MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + "whitenoise.middleware.WhiteNoiseMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "corsheaders.middleware.CorsMiddleware", + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', + ] # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.2/howto/static-files/ @@ -348,23 +377,6 @@ SIMPLE_JWT = { CORS_ALLOW_ALL_ORIGINS = True CORS_ALLOW_CREDENTIALS = True -LOGGING = { - "version": 1, - "disable_existing_loggers": False, - "handlers": { - "console": { - "class": "logging.StreamHandler", - }, - }, - "root": { - "handlers": ["console"], - "level": "DEBUG", - }, -} -DJANGO_LOG_LEVEL = "DEBUG" -# Enables VS Code debugger to break on raised exceptions -DEBUG_PROPAGATE_EXCEPTIONS = "DEBUG" - # Celery Configuration Options CELERY_TIMEZONE = TIME_ZONE CELERY_TASK_TRACK_STARTED = True