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
This commit is contained in:
Mish 2026-01-23 00:02:50 +00:00 committed by GitHub
parent 541d131622
commit 2415abd4b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 11 additions and 5 deletions

View file

@ -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"
APP_TITLE="helper heidi"
PROGRAM="summer_of_making"
HACK_CLUB_AI_API_KEY="sk-hc-v1-..."
BASE_URL="https://..."

View file

@ -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)

View file

@ -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")

View file

@ -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 {

View file

@ -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...",
},
],