diff --git a/backend/settings/dev.py b/backend/settings/dev.py index a8ffd0c6..425dce7f 100644 --- a/backend/settings/dev.py +++ b/backend/settings/dev.py @@ -36,7 +36,9 @@ 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', - 'whitenoise.runserver_nostatic', # < Per Whitenoise, to disable built in + # disable Django’s static file handling and allow WhiteNoise to take over + # http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development + 'whitenoise.runserver_nostatic', 'django.contrib.staticfiles', 'rest_framework', 'backend.api', @@ -44,6 +46,8 @@ MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', + # WhiteNoise middleware should be placed directly after the Django SecurityMiddleware + # http://whitenoise.evans.io/en/stable/django.html#enable-whitenoise 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -58,7 +62,7 @@ TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - # Add dist to + # use templates generated by vue (must match vue.config.js's outputDir) 'DIRS': ['dist'], 'APP_DIRS': True, 'OPTIONS': { @@ -121,23 +125,12 @@ # When Vue Builds, path will be `/static/css/...` so we will have Django Serve # In Production, it's recommended use an alternative approach such as: # http://whitenoise.evans.io/en/stable/django.html?highlight=django - -MIDDLEWARE_CLASSES = ( - 'whitenoise.middleware.WhiteNoiseMiddleware', -) - STATIC_URL = '/static/' # Place static in the same location as webpack build files +# STATIC_ROOT must match vue.config.js's outputDir + assetsDir +# http://whitenoise.evans.io/en/stable/django.html#make-sure-staticfiles-is-configured-correctly STATIC_ROOT = os.path.join(BASE_DIR, 'dist', 'static') STATICFILES_DIRS = [] - -########## -# STATIC # -########## - +# http://whitenoise.evans.io/en/stable/django.html?highlight=django#add-compression-and-caching-support STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' - -# Insert Whitenoise Middleware at top but below Security Middleware -# MIDDLEWARE.insert(1, 'whitenoise.middleware.WhiteNoiseMiddleware',) -# http://whitenoise.evans.io/en/stable/django.html#make-sure-staticfiles-is-configured-correctly