diff --git a/.env.dev.example b/.env.dev.example index 6df74efd7..31694969d 100644 --- a/.env.dev.example +++ b/.env.dev.example @@ -3,6 +3,7 @@ SECRET_KEY="7(2w1sedok=aznpq)ta1mc4i%4h=xx@hxwx*o57ctsuml0x%fr" # SECURITY WARNING: don't run with debug turned on in production! DEBUG=true +USE_HTTPS=false DOMAIN=your.domain.here #EMAIL=your@email.here @@ -42,9 +43,6 @@ EMAIL_HOST_PASSWORD=emailpassword123 EMAIL_USE_TLS=true EMAIL_USE_SSL=false -# Set this to true when initializing certbot for domain, false when not -CERTBOT_INIT=false - # S3 configuration # Commented are example values if you use Scaleway instead of AWS USE_S3=false diff --git a/.env.prod.example b/.env.prod.example index a61a0279a..69578a774 100644 --- a/.env.prod.example +++ b/.env.prod.example @@ -3,6 +3,7 @@ SECRET_KEY="7(2w1sedok=aznpq)ta1mc4i%4h=xx@hxwx*o57ctsuml0x%fr" # SECURITY WARNING: don't run with debug turned on in production! DEBUG=false +USE_HTTPS=true DOMAIN=your.domain.here EMAIL=your@email.here @@ -42,9 +43,6 @@ EMAIL_HOST_PASSWORD=emailpassword123 EMAIL_USE_TLS=true EMAIL_USE_SSL=false -# Set this to true when initializing certbot for domain, false when not -CERTBOT_INIT=false - # S3 configuration # Commented are example values if you use Scaleway instead of AWS USE_S3=false diff --git a/bookwyrm/context_processors.py b/bookwyrm/context_processors.py index 79a113837..1f0387fe7 100644 --- a/bookwyrm/context_processors.py +++ b/bookwyrm/context_processors.py @@ -11,7 +11,7 @@ def site_settings(request): # pylint: disable=unused-argument return { "site": models.SiteSettings.objects.get(), "active_announcements": models.Announcement.active_announcements(), - "media_path": settings.MEDIA_PATH, + "media_full_url": settings.MEDIA_FULL_URL, "preview_images_enabled": settings.ENABLE_PREVIEW_IMAGES, "request_protocol": request_protocol, } diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index a584ae807..39ff668cd 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -58,6 +58,7 @@ SECRET_KEY = env("SECRET_KEY") # SECURITY WARNING: don't run with debug turned on in production! DEBUG = env.bool("DEBUG", True) +USE_HTTPS = env.bool("USE_HTTPS", False) ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", ["*"]) @@ -193,6 +194,10 @@ PROJECT_DIR = os.path.dirname(os.path.abspath(__file__)) # Storage +PROTOCOL = "http" +if USE_HTTPS: + PROTOCOL = "https" + USE_S3 = env.bool("USE_S3", False) if USE_S3: @@ -212,13 +217,14 @@ if USE_S3: # S3 Media settings MEDIA_LOCATION = "images" MEDIA_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, MEDIA_LOCATION) - MEDIA_PATH = "%s/%s" % (AWS_S3_CUSTOM_DOMAIN, MEDIA_LOCATION) + MEDIA_FULL_URL = MEDIA_URL DEFAULT_FILE_STORAGE = "bookwyrm.storage_backends.ImagesStorage" # I don't know if it's used, but the site crashes without it + STATIC_ROOT = os.path.join(BASE_DIR, env("STATIC_ROOT", "static")) MEDIA_ROOT = os.path.join(BASE_DIR, env("MEDIA_ROOT", "images")) else: STATIC_URL = "/static/" STATIC_ROOT = os.path.join(BASE_DIR, env("STATIC_ROOT", "static")) MEDIA_URL = "/images/" - MEDIA_PATH = "https://%s/%s" % (DOMAIN, env("MEDIA_ROOT", "images")) + MEDIA_FULL_URL = "%s://%s%s" % (PROTOCOL, DOMAIN, MEDIA_URL) MEDIA_ROOT = os.path.join(BASE_DIR, env("MEDIA_ROOT", "images")) diff --git a/bookwyrm/templates/snippets/opengraph_images.html b/bookwyrm/templates/snippets/opengraph_images.html index 1f07a1e1e..9668c3d65 100644 --- a/bookwyrm/templates/snippets/opengraph_images.html +++ b/bookwyrm/templates/snippets/opengraph_images.html @@ -2,13 +2,13 @@ {% if preview_images_enabled is True %} {% if image %} - - + + {% else %} - - + + {% endif %} {% else %} - - + + {% endif %}