1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-19 04:49:37 +02:00

static hosting

This commit is contained in:
Sean Morley 2024-07-09 09:58:52 -04:00
parent 7b9023dd07
commit e33654a6b6
5 changed files with 23 additions and 4 deletions

5
backend/.gitignore vendored
View file

@ -113,4 +113,7 @@ demo/react-spa/yarn.lock
# Visual Studio Code # Visual Studio Code
.vscode/ .vscode/
*/media/* */media/*
/static/*
/staticfiles/*

View file

@ -24,6 +24,8 @@ RUN pip install -r requirements.txt
# Copy the Django project code into the Docker image # Copy the Django project code into the Docker image
COPY ./server /code/ COPY ./server /code/
RUN python3 manage.py collectstatic --verbosity 2
# Set the entrypoint script # Set the entrypoint script
COPY ./entrypoint.sh /code/entrypoint.sh COPY ./entrypoint.sh /code/entrypoint.sh
RUN chmod +x /code/entrypoint.sh RUN chmod +x /code/entrypoint.sh

View file

@ -13,6 +13,7 @@ import os
from dotenv import load_dotenv from dotenv import load_dotenv
from datetime import timedelta from datetime import timedelta
from os import getenv from os import getenv
from pathlib import Path
# Load environment variables from .env file # Load environment variables from .env file
load_dotenv() load_dotenv()
@ -61,6 +62,7 @@ INSTALLED_APPS = (
) )
MIDDLEWARE = ( MIDDLEWARE = (
'whitenoise.middleware.WhiteNoiseMiddleware',
'corsheaders.middleware.CorsMiddleware', 'corsheaders.middleware.CorsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
@ -69,6 +71,7 @@ MIDDLEWARE = (
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
'allauth.account.middleware.AccountMiddleware', 'allauth.account.middleware.AccountMiddleware',
) )
# For backwards compatibility for Django 1.8 # For backwards compatibility for Django 1.8
@ -117,7 +120,11 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/ # 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/' STATIC_URL = '/static/'
MEDIA_URL = '/media/' MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')] # STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
@ -151,6 +158,12 @@ REST_AUTH = {
} }
STORAGES = {
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
}
AUTH_USER_MODEL = 'users.CustomUser' AUTH_USER_MODEL = 'users.CustomUser'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

View file

@ -8,4 +8,5 @@ django-cors-headers==4.4.0
coreapi==2.3.3 coreapi==2.3.3
python-dotenv python-dotenv
psycopg2-binary psycopg2-binary
Pillow Pillow
whitenoise

View file

@ -23,8 +23,8 @@ services:
- postgres_data:/var/lib/postgresql/data/ - postgres_data:/var/lib/postgresql/data/
server: server:
# build: ./backend/ build: ./backend/
image: ghcr.io/seanmorley15/adventurelog-backend:latest #image: ghcr.io/seanmorley15/adventurelog-backend:latest
environment: environment:
- PGHOST=db - PGHOST=db
- PGDATABASE=database - PGDATABASE=database