#!/bin/bash
set -e

# 设置环境变量
export SERVER_PORT="5000"
export AUTH_JWT_SECRET="super-secret-jwt-token-with-at-least-32-characters-long"
export AUTH_JWT_ALGORITHM="HS256"
export DATABASE_URL="postgres://supabase_admin:postgres@db:5432/postgres"
export DATABASE_POOL_URL="postgresql://postgres:postgres@127.0.0.1:6432/postgres"
export DB_INSTALL_ROLES="true"
export STORAGE_BACKEND="file"

# 等待 gotrue 服务可用（健康检查）
until curl -s http://localhost:9999/ >/dev/null 2>&1; do
  echo "Waiting for gotrue..."
  sleep 1
done

# 启动 Node 应用
exec node /supabase/storage-ai/dist/start/server.js
