#!/usr/bin/env bash
set -euo pipefail

project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
frontend_pid=""

cleanup() {
    if [[ -n "$frontend_pid" ]] && kill -0 "$frontend_pid" 2>/dev/null; then
        kill "$frontend_pid"
        wait "$frontend_pid" 2>/dev/null || true
    fi
}
trap cleanup EXIT INT TERM

(cd "$project_root/frontend" && exec pnpm dev) &
frontend_pid=$!

echo "H5：http://127.0.0.1:5173"
echo "管理后台：http://127.0.0.1:5174"
echo "后端API：http://127.0.0.1:8000/docs"
cd "$project_root/backend"
uv run uvicorn zbt.main:app --host 127.0.0.1 --port 8000 --reload
