Add SITE_BASE_URL to config #456

Closed
opened 2026-09-02 20:47:31 +02:00 by johnsturgeon · 0 comments
Owner

https://tgfp.us is hardcoded in five places and derived from proxy headers in
several more. It belongs in Config once, as SITE_BASE_URL.

Hardcoded today

app/jobs/announce_picks_page.py:13   " Go to https://tgfp.us/picks and get 'em in!"
app/jobs/nag_players.py:51           " Go to https://tgfp.us/picks and get 'em in!"
app/jobs/award_notify_discord.py:22  url="https://tgfp.us"
app/jobs/award_notify_discord.py:23  icon_url="https://tgfp.us/static/images/tgfp_logo_background.png"
app/jobs/award_notify_discord.py:33  url=f"https://tgfp.us/static/images/{award.award.icon}-med.png"
app/mailer.py:70                     "homepage_url": "https://tgfp.us"
app/mailer.py:71                     "picks_url": "https://tgfp.us/picks"

The two in mailer.py arrived with #209.

Built from the request today

app/mailer.py builds absolute URLs from request.url_for, which is why
send_welcome_email and send_picks_page_ready_email both take a Request
they otherwise have no use for:

app/mailer.py:56  "homepage_url": str(request.url_for("home"))
app/mailer.py:57  "rules_url":    str(request.url_for("rules"))

send_picks_page_ready_email already dropped its Request in #209 by
hardcoding instead; send_welcome_email is the one still holding one.

Two problems with that. A job has no request, so anything sent outside the
request cycle cannot use it -- which is the whole reason #453 happened. And
inside a request it derives scheme and host from proxy headers, so a link
someone clicks a week later is only correct if Pangolin is forwarding them
right. A link in an email should come from configuration, not from whatever
host header happened to arrive.

Switching those four to SITE_BASE_URL lets both mailer functions drop their
Request parameter entirely.

Leave alone

request.url_for for redirects inside the app is correct and should stay:

app/routers/v2.py:97, :110
app/main.py:552
app/routers/auth.py:82, :90

Those are same-request navigation, not links handed to someone else.

Note

Pairs with #452, which strips the vestigial API_BASE_URL (https://tgfp.us/api,
consumed by nothing). One variable out, one in -- no net change for #199.

`https://tgfp.us` is hardcoded in five places and derived from proxy headers in several more. It belongs in `Config` once, as `SITE_BASE_URL`. ## Hardcoded today ``` app/jobs/announce_picks_page.py:13 " Go to https://tgfp.us/picks and get 'em in!" app/jobs/nag_players.py:51 " Go to https://tgfp.us/picks and get 'em in!" app/jobs/award_notify_discord.py:22 url="https://tgfp.us" app/jobs/award_notify_discord.py:23 icon_url="https://tgfp.us/static/images/tgfp_logo_background.png" app/jobs/award_notify_discord.py:33 url=f"https://tgfp.us/static/images/{award.award.icon}-med.png" app/mailer.py:70 "homepage_url": "https://tgfp.us" app/mailer.py:71 "picks_url": "https://tgfp.us/picks" ``` The two in `mailer.py` arrived with #209. ## Built from the request today `app/mailer.py` builds absolute URLs from `request.url_for`, which is why `send_welcome_email` and `send_picks_page_ready_email` both take a `Request` they otherwise have no use for: ``` app/mailer.py:56 "homepage_url": str(request.url_for("home")) app/mailer.py:57 "rules_url": str(request.url_for("rules")) ``` `send_picks_page_ready_email` already dropped its `Request` in #209 by hardcoding instead; `send_welcome_email` is the one still holding one. Two problems with that. A job has no request, so anything sent outside the request cycle cannot use it -- which is the whole reason #453 happened. And inside a request it derives scheme and host from proxy headers, so a link someone clicks a week later is only correct if Pangolin is forwarding them right. A link in an email should come from configuration, not from whatever host header happened to arrive. Switching those four to `SITE_BASE_URL` lets both mailer functions drop their `Request` parameter entirely. ## Leave alone `request.url_for` for redirects inside the app is correct and should stay: ``` app/routers/v2.py:97, :110 app/main.py:552 app/routers/auth.py:82, :90 ``` Those are same-request navigation, not links handed to someone else. ## Note Pairs with #452, which strips the vestigial `API_BASE_URL` (`https://tgfp.us/api`, consumed by nothing). One variable out, one in -- no net change for #199.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
johnsturgeon/tgfp-web#456
No description provided.