From 7ef7cdffa8721b3840264df4224037d09b21d030 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Fri, 2 Apr 2021 15:12:55 -0400 Subject: [PATCH] heroku deployment --- Procfile | 1 + requirements.txt | 10 ++++++++++ timer_backend/settings.py | 13 ++++++++++--- 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 Procfile create mode 100644 requirements.txt diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..f8c5443 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: gunicorn django_rest_api.wsgi diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e3242ca --- /dev/null +++ b/requirements.txt @@ -0,0 +1,10 @@ +asgiref==3.3.1 +dj-database-url==0.5.0 +Django==3.1.7 +django-cors-headers==3.7.0 +djangorestframework==3.12.4 +gunicorn==20.1.0 +psycopg2-binary==2.8.6 +pytz==2021.1 +sqlparse==0.4.1 +whitenoise==5.2.0 diff --git a/timer_backend/settings.py b/timer_backend/settings.py index 6ffadf6..ed723a8 100644 --- a/timer_backend/settings.py +++ b/timer_backend/settings.py @@ -11,9 +11,11 @@ https://docs.djangoproject.com/en/3.1/ref/settings/ """ from pathlib import Path +import dj_database_url +import os # Build paths inside the project like this: BASE_DIR / 'subdir'. -BASE_DIR = Path(__file__).resolve().parent.parent +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production @@ -25,7 +27,7 @@ SECRET_KEY = 'kwuq4$3jeof1(0!k7)+1@40t5s3pe5uo2-amnsl50rsrhwncs0' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ['localhost', 'shrouded-depths-07664.herokuapp.com'] # Application definition @@ -44,6 +46,7 @@ INSTALLED_APPS = [ MIDDLEWARE = [ 'corsheaders.middleware.CorsMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -53,7 +56,7 @@ MIDDLEWARE = [ 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] CORS_ALLOW_ALL_ORIGINS = True - +STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' ROOT_URLCONF = 'timer_backend.urls' TEMPLATES = [ @@ -88,6 +91,9 @@ DATABASES = { } } +db_from_env = dj_database_url.config(conn_max_age=600) +DATABASES['default'].update(db_from_env) + # Password validation # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators @@ -125,3 +131,4 @@ USE_TZ = True # https://docs.djangoproject.com/en/3.1/howto/static-files/ STATIC_URL = '/static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')