diff --git a/builder/build.sh b/builder/build.sh index 6568ca4..67e7b30 100755 --- a/builder/build.sh +++ b/builder/build.sh @@ -126,17 +126,25 @@ if curl --silent --fail "${CADDY_API}/config/" >/dev/null 2>&1; then EOF ) # Upsert the route for this app. - ROUTES=$(curl --silent "${CADDY_API}/config/apps/http/servers/hiy/routes" 2>/dev/null || echo "[]") - # Remove existing route for the same host, then append the new one. + ROUTES=$(curl --silent --fail "${CADDY_API}/config/apps/http/servers/hiy/routes" 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 -routes = json.load(sys.stdin) +try: + routes = json.loads(sys.stdin.read()) + if not isinstance(routes, list): + routes = [] +except Exception: + routes = [] +DASHBOARD = {'handle': [{'handler': 'reverse_proxy', 'upstreams': [{'dial': 'server:3000'}]}]} new_host = '${APP_ID}.${DOMAIN_SUFFIX}' +# Keep host-matched routes that are NOT for this app routes = [r for r in routes - if not (isinstance(r, dict) - and any(isinstance(m, dict) and new_host in m.get('host', []) - for m in r.get('match', [])))] + if r.get('match') and not any( + isinstance(m, dict) and new_host in m.get('host', []) + for m in r.get('match', []))] routes.insert(0, json.loads(sys.argv[1])) +routes.append(DASHBOARD) print(json.dumps(routes)) " "$ROUTE_JSON")