Skip to content

Commit

Permalink
Fix local static files when using uvicorn
Browse files Browse the repository at this point in the history
  • Loading branch information
sarayourfriend committed Jul 21, 2023
1 parent cd6e699 commit b1bbc1d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
13 changes: 8 additions & 5 deletions api/conf/settings/static.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from decouple import config
"""
Static files (CSS, JavaScript, Images)
https://docs.djangoproject.com/en/4.2/howto/static-files/
"""

from decouple import config

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

# Where to collect static files in production/development deployments
STATIC_ROOT = config("STATIC_ROOT", default="/var/api_static_content/static")
# Static files only served by Django in local environments
# In live environments, the files are served by Nginx, copied out of the Django image
STATIC_ROOT = config("STATIC_ROOT", default="/static")

STATIC_URL = "static/"
5 changes: 5 additions & 0 deletions api/conf/urls/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
https://docs.djangoproject.com/en/4.2/topics/http/urls/
"""

from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path
from django.views.generic import RedirectView
Expand Down Expand Up @@ -37,3 +39,6 @@
path("healthcheck/", HealthCheck.as_view(), name="health"),
path("v1/", include(versioned_paths)),
]

if settings.ENVIRONMENT == "local":
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
4 changes: 2 additions & 2 deletions api/env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ DJANGO_SECRET_KEY="ny#b__$$f6ry4wy8oxre97&-68u_0lk3gw(z=d40_dxey3zw0v1"
DJANGO_DEBUG_ENABLED=True

BASE_URL=http://localhost:50280/
ENVIRONMENT=development
ALLOWED_HOSTS=api.openverse.engineering,api-dev.openverse.engineering,host.docker.internal
ENVIRONMENT=local
ALLOWED_HOSTS=localhost,172.17.0.1,host.docker.internal

REDIS_HOST=cache

Expand Down
5 changes: 0 additions & 5 deletions api/env.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ DJANGO_SETTINGS_MODULE=conf.settings
DJANGO_SECRET_KEY="ny#b__$$f6ry4wy8oxre97&-68u_0lk3gw(z=d40_dxey3zw0v1"
DJANGO_DEBUG_ENABLED=True

BASE_URL=http://localhost:50280/
ENVIRONMENT=development
# List of comma-separated hosts/domain names, e.g., 127.17.0.1,local.app
ALLOWED_HOSTS=localhost,172.17.0.1,host.docker.internal

#LOAD_BALANCER_URL=

#USE_S3=False
Expand Down
4 changes: 0 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,13 @@ services:
- ./api:/api
ports:
- "50280:8000" # Django
- "50230:3000" # Sphinx (unused by default; see `sphinx-live` recipe)
depends_on:
- db
- es
- cache
env_file:
- api/env.docker
- api/.env
environment:
STATIC_ROOT: ${STATIC_ROOT:-}
MEDIA_ROOT: ${MEDIA_ROOT:-}
stdin_open: true
tty: true

Expand Down

0 comments on commit b1bbc1d

Please sign in to comment.