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."