#!/bin/bash
set -euo pipefail

echo "[chatai-ui] Waiting for Kong to proxy PostgREST..."

until curl -sSf http://localhost:8000/rest/v1/health > /dev/null 2>&1; do
  echo "[chatai-ui] Still waiting for API route /rest/v1/health..."
  sleep 1
done

echo "[chatai-ui] API is reachable via Kong. Starting UI..."

cd /supabase/chatai-ui
exec npm run start
