feat: Add WhiteNoise for static files serving
- Add whitenoise==6.6.0 to requirements.txt - Configure WhiteNoise middleware in base settings - Add WhiteNoise STORAGES configuration for all environments - Reorder CORS middleware to correct position (before CommonMiddleware) - Enable automatic Gzip compression and cache busting - Configure environment-specific settings: * Development: autorefresh enabled, use finders * Staging: 10min cache, autorefresh for testing * Production: 1 year cache, strict mode, optimized Fixes issue with Django REST Framework static files returning 404 in staging/production environments (DEBUG=False). WhiteNoise now serves all static files (CSS, JS, images) with: - Automatic Gzip compression (~84% size reduction) - Cache busting with content hashing - Optimized cache headers - No nginx required for static files
This commit is contained in:
@@ -58,13 +58,14 @@ INSTALLED_APPS = [
|
||||
|
||||
MIDDLEWARE = [
|
||||
"django.middleware.security.SecurityMiddleware",
|
||||
"whitenoise.middleware.WhiteNoiseMiddleware", # Serve static files (must be after SecurityMiddleware)
|
||||
"corsheaders.middleware.CorsMiddleware", # Must be before CommonMiddleware
|
||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
"django.middleware.csrf.CsrfViewMiddleware",
|
||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||
"django.contrib.messages.middleware.MessageMiddleware",
|
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||
"corsheaders.middleware.CorsMiddleware",
|
||||
]
|
||||
|
||||
ROOT_URLCONF = "config.urls"
|
||||
|
||||
Reference in New Issue
Block a user