#!/usr/bin/env bash
# Restart the frontend dev server.
# Usage: bash scripts/restart-frontend.sh

set -e
cd "$(dirname "$0")/.."

# Kill existing frontend
PID=$(netstat -ano 2>/dev/null | grep ':5175.*LISTENING' | awk '{print $5}' | head -1)
if [ -n "$PID" ]; then
  taskkill //F //PID "$PID" 2>/dev/null || true
  sleep 1
fi

# Start frontend
cd frontend
npx vite dev --port 5175 --host > /dev/null 2>&1 &
cd ..

sleep 4
curl -s -o /dev/null -w "Frontend: %{http_code}\n" http://localhost:5175/
