Skip to content

Commit

Permalink
static hosting
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmorley15 committed Jul 9, 2024
1 parent 7b9023d commit e33654a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
5 changes: 4 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,7 @@ demo/react-spa/yarn.lock
# Visual Studio Code
.vscode/

*/media/*
*/media/*

/static/*
/staticfiles/*
2 changes: 2 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ RUN pip install -r requirements.txt
# Copy the Django project code into the Docker image
COPY ./server /code/

RUN python3 manage.py collectstatic --verbosity 2

# Set the entrypoint script
COPY ./entrypoint.sh /code/entrypoint.sh
RUN chmod +x /code/entrypoint.sh
Expand Down
13 changes: 13 additions & 0 deletions backend/server/demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from dotenv import load_dotenv
from datetime import timedelta
from os import getenv
from pathlib import Path
# Load environment variables from .env file
load_dotenv()

Expand Down Expand Up @@ -61,6 +62,7 @@
)

MIDDLEWARE = (
'whitenoise.middleware.WhiteNoiseMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
Expand All @@ -69,6 +71,7 @@
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'allauth.account.middleware.AccountMiddleware',

)

# For backwards compatibility for Django 1.8
Expand Down Expand Up @@ -117,7 +120,11 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/


BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_ROOT = BASE_DIR / "staticfiles"
STATIC_URL = '/static/'

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
Expand Down Expand Up @@ -151,6 +158,12 @@

}

STORAGES = {
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
}

AUTH_USER_MODEL = 'users.CustomUser'

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
Expand Down
3 changes: 2 additions & 1 deletion backend/server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ django-cors-headers==4.4.0
coreapi==2.3.3
python-dotenv
psycopg2-binary
Pillow
Pillow
whitenoise
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ services:
- postgres_data:/var/lib/postgresql/data/

server:
# build: ./backend/
image: ghcr.io/seanmorley15/adventurelog-backend:latest
build: ./backend/
#image: ghcr.io/seanmorley15/adventurelog-backend:latest
environment:
- PGHOST=db
- PGDATABASE=database
Expand Down

0 comments on commit e33654a

Please sign in to comment.