From 2415abd4b176212a5fbfdc2df84b546dfb206790 Mon Sep 17 00:00:00 2001 From: Mish Date: Fri, 23 Jan 2026 00:02:50 +0000 Subject: [PATCH] Fix selfhosted images being served incorrectly (#148) * Rename HOSTNAME env var to BASE_URL (and document it) * BASE_URL.rstrip("/") Prevent errors if you include / in your env var * Trailing newline --- .env.sample | 6 ++++-- docs/deployment.md | 2 ++ nephthys/utils/env.py | 4 +++- nephthys/views/home/components/ticket_status_pie.py | 2 +- nephthys/views/home/loading.py | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.env.sample b/.env.sample index dfd08ba..cd9939c 100644 --- a/.env.sample +++ b/.env.sample @@ -12,5 +12,7 @@ SLACK_MAINTAINER_ID="U..." DATABASE_URL="postgresql://postgres:postgres@localhost:5432/nephthys" SITE_URL="https://summer.hackclub.com" SITE_API_KEY="..." -# Title shown in app home: -APP_TITLE="helper heidi" \ No newline at end of file +APP_TITLE="helper heidi" +PROGRAM="summer_of_making" +HACK_CLUB_AI_API_KEY="sk-hc-v1-..." +BASE_URL="https://..." diff --git a/docs/deployment.md b/docs/deployment.md index 93bffd5..c91d0bd 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -75,6 +75,8 @@ Note: These steps have to be done by a Workspace Admin (otherwise it will be una HACK_CLUB_AI_API_KEY="sk-hc-v1-..." # Set this to anything SITE_API_KEY="none" + # Set this to the URL where the site will be hosted + BASE_URL="https://summer.nephthys.hackclub.com" ``` - `SITE_API_KEY` (and `SITE_URL`) are only used for generating magic links for Summer of Making, so they don't have to be included (but `SITE_API_KEY` must be set due to a bug) diff --git a/nephthys/utils/env.py b/nephthys/utils/env.py index cb8e543..9a9199f 100644 --- a/nephthys/utils/env.py +++ b/nephthys/utils/env.py @@ -41,7 +41,9 @@ class Environment: or default_log_level ) self.log_level_otel = os.environ.get("LOG_LEVEL_OTEL", logging.INFO) - self.hostname: str = os.environ.get("HOSTNAME", "https://nephthys.hackclub.com") + self.base_url: str = os.environ.get( + "BASE_URL", "https://nephthys.hackclub.com" + ).rstrip("/") self.slack_help_channel = os.environ.get("SLACK_HELP_CHANNEL", "unset") self.slack_ticket_channel = os.environ.get("SLACK_TICKET_CHANNEL", "unset") diff --git a/nephthys/views/home/components/ticket_status_pie.py b/nephthys/views/home/components/ticket_status_pie.py index 0a293b0..ce775e5 100644 --- a/nephthys/views/home/components/ticket_status_pie.py +++ b/nephthys/views/home/components/ticket_status_pie.py @@ -89,7 +89,7 @@ async def get_ticket_status_pie_chart( caption = "Ticket stats" if not url: - url = f"{env.hostname}/public/binoculars.png" + url = f"{env.base_url}/public/binoculars.png" caption = "looks like heidi's scrounging around for tickets in the trash" return { diff --git a/nephthys/views/home/loading.py b/nephthys/views/home/loading.py index d1a2980..75fd6be 100644 --- a/nephthys/views/home/loading.py +++ b/nephthys/views/home/loading.py @@ -16,7 +16,7 @@ def get_loading_view(home_type: str): }, { "type": "image", - "image_url": f"{env.hostname}/public/loading.gif", + "image_url": f"{env.base_url}/public/loading.gif", "alt_text": "Loading...", }, ],