Repository navigation
Expand file tree
/
Copy pathproduction.py
More file actions
65 lines (54 loc) · 1.88 KB
/
Copy pathproduction.py
File metadata and controls
65 lines (54 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# ruff: noqa
import os
import dj_database_url
from .base import *
# Disable debug mode
DEBUG = False
# Security / HTTPS hardening
# Heroku terminates TLS at the router and forwards plain HTTP to the dyno,
# so Django must trust the X-Forwarded-Proto header to detect HTTPS.
# Without this, SECURE_SSL_REDIRECT would cause an infinite redirect loop.
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SECURE_HSTS_SECONDS = 31536000 # 1 year
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_HSTS_PRELOAD = True
# Persistent database connections with TLS for Heroku Postgres.
# Avoids opening a new TCP+TLS connection on every request.
DATABASES = {
"default": dj_database_url.config(
conn_max_age=600,
conn_health_checks=True,
ssl_require=True,
)
}
# AWS S3 Storage Configuration
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
AWS_STORAGE_BUCKET_NAME = os.getenv("AWS_STORAGE_BUCKET_NAME")
AWS_S3_CUSTOM_DOMAIN = "s3.python.ie"
AWS_HOST = "s3-eu-west-1.amazonaws.com"
AWS_DEFAULT_ACL = "public-read"
# Don't silently overwrite/delete user-uploaded files that share a name
# (Wagtail recommends False; see wagtailadmin.W004).
AWS_S3_FILE_OVERWRITE = False
# Use S3 for media files (Django 5.1+ STORAGES API)
STORAGES = {
"default": {
"BACKEND": "storages.backends.s3boto3.S3Boto3Storage",
},
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
}
MEDIA_URL = f"https://{AWS_S3_CUSTOM_DOMAIN}/"
# Compress static files offline
# http://django-compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE
COMPRESS_OFFLINE = False
CSRF_TRUSTED_ORIGINS = ["https://python.ie"]
try:
from .local import * # noqa
except ImportError:
pass