#!/usr/bin/env bash set -Eeuo pipefail LOCAL_BASE="${LANDWELLE_LOCAL_API_BASE:-http://127.0.0.1:2200}" PUBLIC_BASE="${LANDWELLE_PUBLIC_API_BASE:-https://api.landwelle.de}" TMP_DIR="$(mktemp -d)" trap 'rm -rf "$TMP_DIR"' EXIT check_endpoint() { local label="$1" local url="$2" local expected_content_type="$3" local headers="$TMP_DIR/${label}.headers" local body="$TMP_DIR/${label}.body" local status status="$(curl -sS --connect-timeout 5 --max-time 20 -D "$headers" -o "$body" -w '%{http_code}' "$url" || true)" printf '%-28s %s HTTP %s\n' "$label" "$url" "$status" if [[ "$status" != "200" ]]; then echo " FEHLER: Erwartet wurde HTTP 200." if [[ -s "$body" ]]; then echo " Antwort: $(tr '\n' ' ' < "$body" | head -c 240)" echo fi return 1 fi if ! grep -qi "content-type:.*${expected_content_type}" "$headers"; then echo " FEHLER: Unerwarteter Content-Type." sed -n '1,20p' "$headers" | sed 's/^/ /' return 1 fi echo " OK" } local_ok=0 public_ok=0 if check_endpoint "lokale Web-API" "$LOCAL_BASE/api/v1/now" "application/json"; then local_ok=1 fi if check_endpoint "öffentliche Web-API" "$PUBLIC_BASE/api/v1/now" "application/json"; then public_ok=1 fi check_endpoint "öffentliche Web-API-Kontrolle" "${PUBLIC_BASE}/api/v1/now" "application/json" || true check_endpoint "öffentlicher Healthcheck" "$PUBLIC_BASE/health" "application/json" || true if [[ "$local_ok" -eq 1 && "$public_ok" -eq 0 ]]; then cat <<'MSG' DIAGNOSE: Die Go-API läuft lokal, aber die API-Subdomain reicht /api/v1 nicht weiter. In KeyHelp bei api.landwelle.de das vollständige Fragment „deploy/keyhelp-api-subdomain-https.conf“ in „Anweisungen für HTTPS“ eintragen, speichern und die Webserver-Konfiguration neu laden lassen. MSG exit 2 fi if [[ "$local_ok" -ne 1 ]]; then cat <<'MSG' DIAGNOSE: Die API antwortet bereits lokal nicht korrekt. Portalstatus prüfen: systemctl status landwelle-radio --no-pager curl -i http://127.0.0.1:2200/api/v1/now MSG exit 3 fi if [[ "$public_ok" -ne 1 ]]; then exit 4 fi echo echo "Landwelle Web-API ist korrekt erreichbar."