Skip to content

Commit

Permalink
deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacfritsch committed Oct 7, 2024
1 parent 23766cf commit 6028c49
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 50 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn quaac.wsgi --log-file - --capture-output
131 changes: 81 additions & 50 deletions nasaspaceapp2024/settings.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
"""
Django settings for nasaspaceapp2024 project.
Generated by 'django-admin startproject' using Django 5.1.1.
For more information on this file, see
https://docs.djangoproject.com/en/5.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.1/ref/settings/
"""

from pathlib import Path
from decouple import config
import os
from pathlib import Path
from decouple import config, Csv
import dj_database_url
from urllib.parse import urlparse

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!

SECRET_KEY='django-insecure-@cuio-1^0)p+5bu+z&hw%*y+9w_97t(k_zdh3q^a0wxcmvp4o!'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

IS_HEROKU_APP = "DYNO" in os.environ and not "CI" in os.environ

if not IS_HEROKU_APP:
SECRET_KEY = 'django-insecure-xyz1234567890'
DEBUG = True

if IS_HEROKU_APP:
SECRET_KEY = config('SECRET_KEY')
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default =[''], cast=Csv())
SECURE_BROWSER_XSS_FILTER = True
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_SSL_REDIRECT = True
SECURE_HSTS_SECONDS = 86400
SECURE_HSTS_PRELOAD = True
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
DATABASE_URL = config('DATABASE_URL')
else:
ALLOWED_HOSTS = ['localhost', '127.0.0.1']

if IS_HEROKU_APP:
CACHES = {
'default': {
'BACKEND': 'django_bmemcached.memcached.BMemcached',
'LOCATION': os.environ.get('MEMCACHEDCLOUD_SERVERS').split(','),
'OPTIONS': {
'username': os.environ.get('MEMCACHEDCLOUD_USERNAME'),
'password': os.environ.get('MEMCACHEDCLOUD_PASSWORD')
}
}
}

# Application definition

Expand All @@ -42,15 +50,12 @@
'mapas',
]

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')


MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
Expand All @@ -76,20 +81,27 @@

WSGI_APPLICATION = 'nasaspaceapp2024.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
import psycopg2


if IS_HEROKU_APP:
conn = psycopg2.connect(DATABASE_URL, sslmode='require')
DATABASES = {
'default': dj_database_url.config(conn_max_age=600, ssl_require=True)
}
else:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}

# Password validation
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
Expand All @@ -106,9 +118,8 @@
},
]


# Internationalization
# https://docs.djangoproject.com/en/5.1/topics/i18n/
# https://docs.djangoproject.com/en/5.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

Expand All @@ -118,14 +129,34 @@

USE_TZ = True


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

STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
STATIC_ROOT = BASE_DIR / "staticfiles"
STATIC_URL = "static/"

STATIC_URL = 'static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]

# Default primary key field type
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage", # Sempre usa armazenamento local
},
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", # Para arquivos estáticos
},
}
# Don't store the original (un-hashed filename) version of static files, to reduce slug size:
# https://whitenoise.readthedocs.io/en/latest/django.html#WHITENOISE_KEEP_ONLY_HASHED_FILES
WHITENOISE_KEEP_ONLY_HASHED_FILES = True

# STATICFILES_STORAGE = '.storage.WhiteNoiseStaticFilesStorage'

MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR /'media'
WHITENOISE_MEDIA_ROOT = MEDIA_ROOT

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

X_FRAME_OPTIONS = 'SAMEORIGIN'
Binary file modified requirements.txt
Binary file not shown.

0 comments on commit 6028c49

Please sign in to comment.