From 6ff8c9a2673d4d5d2be6f637f92a5ddc2f42974b Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Mar 2026 13:34:21 +0000 Subject: [PATCH] Fix Caddy route registration: discover server name dynamically Caddy's Caddyfile adapter names servers 'srv0' (not 'hiy'), so PATCHing /config/apps/http/servers/hiy/routes was a no-op. Now we query /config/apps/http/servers/ to find the actual server name before updating routes. https://claude.ai/code/session_01FKCW3FDjNFj6jve4niMFXH --- builder/build.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/builder/build.sh b/builder/build.sh index 4a15394..6603cdd 100755 --- a/builder/build.sh +++ b/builder/build.sh @@ -119,6 +119,14 @@ if curl --silent --fail "${CADDY_API}/config/" >/dev/null 2>&1; then UPSTREAM="${CONTAINER_IP}:${PORT}" log "Updating Caddy: ${APP_ID}.${DOMAIN_SUFFIX} → ${UPSTREAM}" + # Discover actual server name (Caddyfile adapter names it 'srv0', not 'hiy'). + CADDY_SERVER=$(curl --silent "${CADDY_API}/config/apps/http/servers/" 2>/dev/null | \ + python3 -c "import sys,json; d=json.load(sys.stdin); print(next(iter(d)))" 2>/dev/null || true) + if [ -z "$CADDY_SERVER" ]; then + log "WARNING: Could not discover Caddy server name; skipping route update." + else + ROUTES_URL="${CADDY_API}/config/apps/http/servers/${CADDY_SERVER}/routes" + ROUTE_JSON=$(cat </dev/null 2>&1; then EOF ) # Upsert the route for this app. - ROUTES=$(curl --silent --fail "${CADDY_API}/config/apps/http/servers/hiy/routes" 2>/dev/null || echo "[]") + ROUTES=$(curl --silent --fail "${ROUTES_URL}" 2>/dev/null || echo "[]") # Remove existing route for the same host, rebuild list, keep dashboard as catch-all. UPDATED=$(echo "$ROUTES" | python3 -c " import sys, json @@ -154,7 +162,7 @@ print(json.dumps(routes)) set +e CADDY_RESP=$(curl --silent --show-error \ --write-out "\nHTTP_STATUS:%{http_code}" \ - "${CADDY_API}/config/apps/http/servers/hiy/routes" \ + "${ROUTES_URL}" \ --header "Content-Type: application/json" \ --request PATCH \ --data "$UPDATED" 2>&1) @@ -165,6 +173,7 @@ print(json.dumps(routes)) log "WARNING: Caddy update failed (app is running; fix routing manually)." log "Caddy response: ${CADDY_RESP}" fi + fi # end: CADDY_SERVER not empty else log "Caddy admin API not reachable; skipping route update." log "Container ${CONTAINER_NAME} is running on port ${PORT} but not publicly routed."