Restore start.sh from 0.5.5

This commit is contained in:
Andreas Dueren
2025-11-20 14:22:13 -06:00
parent f984184b39
commit 95758de781

View File

@@ -121,67 +121,6 @@ normalize_host() {
esac esac
} }
common_domain_suffix_two() {
local host_a="$1"
local host_b="$2"
local IFS='.'
local -a parts_a=()
local -a parts_b=()
read -ra parts_a <<< "$host_a"
read -ra parts_b <<< "$host_b"
local i=$(( ${#parts_a[@]} - 1 ))
local j=$(( ${#parts_b[@]} - 1 ))
local suffix=""
while [ $i -ge 0 ] && [ $j -ge 0 ]; do
if [ "${parts_a[$i]}" = "${parts_b[$j]}" ]; then
if [ -z "$suffix" ]; then
suffix="${parts_a[$i]}"
else
suffix="${parts_a[$i]}.$suffix"
fi
((i--))
((j--))
else
break
fi
done
printf '%s\n' "$suffix"
}
common_domain_suffix() {
if [ "$#" -eq 0 ]; then
return
fi
local suffix="$1"
shift
while [ "$#" -gt 0 ] && [ -n "$suffix" ]; do
suffix="$(common_domain_suffix_two "$suffix" "$1")"
shift
done
printf '%s\n' "$suffix"
}
derive_default_rp_id() {
local hosts=("$PHOTOS_HOST")
if [ "$USE_SUBDOMAIN_ROUTING" = true ]; then
hosts+=("$ACCOUNTS_HOST" "$AUTH_HOST" "$CAST_HOST" "$ALBUMS_HOST" "$FAMILY_HOST")
fi
local suffix
suffix="$(common_domain_suffix "${hosts[@]}")"
if [ -n "$suffix" ]; then
printf '%s\n' "$suffix"
else
printf '%s\n' "$PHOTOS_HOST"
fi
}
ACCOUNTS_HOST="$(normalize_host "$ACCOUNTS_HOST")" ACCOUNTS_HOST="$(normalize_host "$ACCOUNTS_HOST")"
AUTH_HOST="$(normalize_host "$AUTH_HOST")" AUTH_HOST="$(normalize_host "$AUTH_HOST")"
CAST_HOST="$(normalize_host "$CAST_HOST")" CAST_HOST="$(normalize_host "$CAST_HOST")"
@@ -216,11 +155,7 @@ else
API_BASE="$BASE_URL" API_BASE="$BASE_URL"
fi fi
API_ORIGIN="${API_BASE}/api" API_ORIGIN="${API_BASE}/api"
if [ -n "${WEBAUTHN_RP_ID:-}" ]; then RP_ID="$PHOTOS_HOST"
RP_ID="$WEBAUTHN_RP_ID"
else
RP_ID="$(derive_default_rp_id)"
fi
log INFO "Application base URL: $BASE_URL" log INFO "Application base URL: $BASE_URL"
log INFO "Relying party ID: $RP_ID" log INFO "Relying party ID: $RP_ID"
@@ -1054,8 +989,7 @@ cat > "$CADDY_CONFIG" <<EOF_CADDY
respond 204 respond 204
} }
@api_host host ${PHOTOS_HOST} handle_path /api/* {
handle_path @api_host /api/* {
@api_cors_subdomain header Origin * @api_cors_subdomain header Origin *
header @api_cors_subdomain { header @api_cors_subdomain {
Access-Control-Allow-Origin {http.request.header.Origin} Access-Control-Allow-Origin {http.request.header.Origin}
@@ -1108,7 +1042,6 @@ cat > "$CADDY_CONFIG" <<EOF_CADDY
} }
@museum_api_get { @museum_api_get {
host ${PHOTOS_HOST}
method GET HEAD method GET HEAD
path_regexp museum_api_get ^/(admin|authenticator|billing|cast|collections|custom-domain|diff|discount|email-hash|emails-from-hashes|emergency-contacts|family|file|file-link|files|fire|info|job|mail|metrics|multipart-upload-urls|offers|options|pass-info|passkeys|public-collection|push|queue|remote-store|storage-bonus|thumbnail|trash|unknown-api|upload-urls|user|user-entity|verify-password)(/|$) path_regexp museum_api_get ^/(admin|authenticator|billing|cast|collections|custom-domain|diff|discount|email-hash|emails-from-hashes|emergency-contacts|family|file|file-link|files|fire|info|job|mail|metrics|multipart-upload-urls|offers|options|pass-info|passkeys|public-collection|push|queue|remote-store|storage-bonus|thumbnail|trash|unknown-api|upload-urls|user|user-entity|verify-password)(/|$)
} }
@@ -1122,7 +1055,6 @@ cat > "$CADDY_CONFIG" <<EOF_CADDY
} }
@write_methods { @write_methods {
host ${PHOTOS_HOST}
not method GET not method GET
not method HEAD not method HEAD
} }
@@ -1218,11 +1150,7 @@ cat > "$CADDY_CONFIG" <<EOF_CADDY
respond 204 respond 204
} }
@api_photos { handle_path /api/* {
host ${PHOTOS_HOST}
path /api/*
}
handle @api_photos {
@api_cors_path header Origin * @api_cors_path header Origin *
header @api_cors_path { header @api_cors_path {
Access-Control-Allow-Origin {http.request.header.Origin} Access-Control-Allow-Origin {http.request.header.Origin}
@@ -1240,7 +1168,6 @@ cat > "$CADDY_CONFIG" <<EOF_CADDY
header_up X-Forwarded-Proto {http.request.header.X-Forwarded-Proto} header_up X-Forwarded-Proto {http.request.header.X-Forwarded-Proto}
} }
} }
}
handle /health { handle /health {
rewrite * /ping rewrite * /ping
@@ -1276,7 +1203,6 @@ cat > "$CADDY_CONFIG" <<EOF_CADDY
} }
@museum_api_get_path { @museum_api_get_path {
host ${PHOTOS_HOST}
method GET HEAD method GET HEAD
path_regexp museum_api_get_path ^/(admin|authenticator|billing|cast|collections|custom-domain|diff|discount|email-hash|emails-from-hashes|emergency-contacts|family|file|file-link|files|fire|info|job|mail|metrics|multipart-upload-urls|offers|options|pass-info|passkeys|public-collection|push|queue|remote-store|storage-bonus|thumbnail|trash|unknown-api|upload-urls|user|user-entity|verify-password)(/|$) path_regexp museum_api_get_path ^/(admin|authenticator|billing|cast|collections|custom-domain|diff|discount|email-hash|emails-from-hashes|emergency-contacts|family|file|file-link|files|fire|info|job|mail|metrics|multipart-upload-urls|offers|options|pass-info|passkeys|public-collection|push|queue|remote-store|storage-bonus|thumbnail|trash|unknown-api|upload-urls|user|user-entity|verify-password)(/|$)
} }
@@ -1290,7 +1216,6 @@ cat > "$CADDY_CONFIG" <<EOF_CADDY
} }
@write_methods_path { @write_methods_path {
host ${PHOTOS_HOST}
not method GET not method GET
not method HEAD not method HEAD
} }