Conversation
- Add /static URL configuration to Django backend - Update Traefik routing to include /static path - Install wget in frontend container for health checks Co-authored-by: pirus99 <206077632+pirus99@users.noreply.github.com>
Co-authored-by: pirus99 <206077632+pirus99@users.noreply.github.com>
There was a problem hiding this comment.
@copilot this does not seem correct, we want to use the global static files endpoint to serve instead of creating a new one ?
There was a problem hiding this comment.
Could you clarify what you mean by "global static files endpoint"? Should I:
- Revert the Django URL changes and serve static files directly from the volume using nginx/Traefik?
- Use WhiteNoise middleware instead of Django's static() helper?
- Something else?
Currently, Traefik routes /static to the backend container (port 8000), and Django serves the files from the volume. What approach would you prefer?
Your comment appears to be cut off. Could you provide the complete error message? It looks like there's a "Refused to apply style from..." error. This is typically a CORS or MIME type issue. The full error message would help me diagnose the problem. |
|
@copilot i mean the static endpoint serverd within runserver command configured in settings.py |
The The If you prefer a different approach, I can:
Which would you prefer? |
Co-authored-by: pirus99 <206077632+pirus99@users.noreply.github.com>
|
@copilot would it make sense to serve static files via nginx frontend container ? but can we copy the static files from backend to frontend ? is therse something to copy ? |
…ectory The static files were collected during Docker build but the volume mount was overwriting them with an empty directory. Now collectstatic runs on container startup after the volume is mounted. Co-authored-by: pirus99 <206077632+pirus99@users.noreply.github.com>
The 404 errors were caused by the volume mount overwriting static files collected during build. Fixed in commit 8e8cf24 by running The static files now populate to Try restarting the containers - the static files should now load correctly. |
|
@copilot static files get not served correctly, plese try to spin up another nginx container that serves the static files for the backend admin panel and the rest framework. After backend build, copy the needed static files to the new container use collect static command to gather the static files. |
- Created static-server with nginx to serve /static files - Reverted urls.py to remove static() helper (Django no longer serves static files) - Reverted entrypoint.sh to remove collectstatic command - Updated Traefik routing: /static now routes to static-server instead of backend - Backend routes only /api and /admin paths - Static files collected during backend build and shared via volume - Added wget to static-server for health checks Co-authored-by: pirus99 <206077632+pirus99@users.noreply.github.com>
- Set static-server priority to 110 (higher than backend's 100) - Ensures /static requests are routed to static-server correctly - Added comment explaining 1-year cache is safe due to Django content hashing Co-authored-by: pirus99 <206077632+pirus99@users.noreply.github.com>
Implemented as requested in commits a52652b and 695160b: ✅ Created dedicated nginx The static-server is now a separate service that efficiently serves static files via nginx, while Django focuses only on the API and admin interface. |
Django admin and DRF static files were collected but not served. Frontend containers failed health checks due to missing
wgetin nginx:alpine.Changes
Dedicated static file server
static-serverservice with nginx to serve Django admin and DRF static filescollectstaticbackend-staticvolume between backend and static-server (read-only mount)STATIC_URLto use absolute path/static/(added leading slash for proper URL resolution)Backend cleanup
backend/core/urls.pyto original state (removedstatic()helper)backend/entrypoint.shto original state (removedcollectstaticcommand)Traefik routing
/apiand/adminonly (priority 100)/staticwith priority 110 (higher for correct routing)Frontend health check
wgetin nginx:alpine container/healthalready configured in nginx.confDocumentation
/staticendpoint availabilityArchitecture
How It Works
collectstaticduring build → files go to/app/staticfilesbackend-staticis mounted at/app/staticfilesin backend container/usr/share/nginx/html/staticin static-server/staticrequests to static-server on port 80This approach follows best practices by separating concerns - Django handles the API while nginx efficiently serves static files.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.