#!/usr/bin/env bash
# Start Nexus FastAPI in WSL dev mode (reload).
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"

bash scripts/wsl_ensure_venv.sh
PY="${ROOT}/.venv/bin/python3"

if ! redis-cli ping 2>/dev/null | grep -q PONG; then
  echo "ERROR: Redis not responding. Run: sudo service redis-server start"
  exit 1
fi

if [[ ! -f .env ]]; then
  echo "WARN: No .env — app runs in INSTALL MODE only."
  echo "  Open http://127.0.0.1:8600/app/install.html after start"
fi

echo "Starting Nexus on http://127.0.0.1:8600 ..."
exec "$PY" -m uvicorn server.main:app --host 127.0.0.1 --port 8600 --reload
