Handle a mirror served under a base path

Deriving the site URL by reducing the mirror URL to its origin discarded any
base path, so a mirror at https://host/abdelpakDelta/mods produced a pack URL
of https://host/packs/<slug> — a location nothing serves. Strip the last path
segment instead, which gives the right answer with or without a base path.

The server address derivation also only stripped scheme and port, so a site URL
carrying a path leaked it into the address shown to players. Strip the path too.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
main
Amir Alexander Abdelbaki 2026-08-05 23:12:40 +02:00
parent b4320303d3
commit 7a84ef3117
1 changed files with 8 additions and 2 deletions

View File

@ -104,12 +104,18 @@ BASEURL="${BASEURL%/}"
# Everything the guides need is derivable from the mirror URL, so one -u is # Everything the guides need is derivable from the mirror URL, so one -u is
# usually enough; each piece can still be overridden individually. # usually enough; each piece can still be overridden individually.
[ -n "$SITE_URL" ] || [ -z "$BASEURL" ] || SITE_URL="$(awk -F/ '{print $1"//"$3}' <<<"$BASEURL")" # Strip the last segment off the mirror URL rather than reducing to the origin,
# so a mirror under a base path keeps it:
# https://host/mods -> https://host
# https://host/abdelpakDelta/mods -> https://host/abdelpakDelta
[ -n "$SITE_URL" ] || [ -z "$BASEURL" ] || SITE_URL="${BASEURL%/*}"
SITE_URL="${SITE_URL%/}" SITE_URL="${SITE_URL%/}"
if [ -n "$SITE_URL" ]; then if [ -n "$SITE_URL" ]; then
[ -n "$PACK_URL" ] || PACK_URL="$SITE_URL/packs/$slug" [ -n "$PACK_URL" ] || PACK_URL="$SITE_URL/packs/$slug"
[ -n "$SERVER_ADDR" ] || SERVER_ADDR="$(sed -e 's#^[a-z]*://##' -e 's#:.*##' <<<"$SITE_URL")" # Host only: strip scheme, then any path, then any port. Dropping the path
# matters once SITE_URL can carry one.
[ -n "$SERVER_ADDR" ] || SERVER_ADDR="$(sed -e 's#^[a-z]*://##' -e 's#/.*##' -e 's#:.*##' <<<"$SITE_URL")"
fi fi
PACK_URL="${PACK_URL%/}" PACK_URL="${PACK_URL%/}"