diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..2804430 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: gunicorn quaac.wsgi --log-file - --capture-output diff --git a/nasaspaceapp2024/settings.py b/nasaspaceapp2024/settings.py index 735e229..4d0cb83 100644 --- a/nasaspaceapp2024/settings.py +++ b/nasaspaceapp2024/settings.py @@ -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 @@ -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', @@ -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 = [ { @@ -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' @@ -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' \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 4590f49..8572250 100644 Binary files a/requirements.txt and b/requirements.txt differ