#!/bin/bash
# Restart Frontend with New HMR Configuration

echo "🔄 Restarting Frontend Service..."
echo "=================================="

# Kill existing Vite process
echo -n "Stopping existing frontend... "
pkill -f "vite.*5100" 2>/dev/null
sleep 2
echo "✓"

# Start new Vite process
echo -n "Starting frontend with new config... "
cd /media/pts/Website/Church_HOP_MusicData/new-site/frontend
nohup npm run dev > /tmp/frontend-vite.log 2>&1 &
FRONTEND_PID=$!
sleep 3

# Check if it started
if ps -p $FRONTEND_PID > /dev/null 2>&1; then
    echo "✓ (PID: $FRONTEND_PID)"
    echo ""
    echo "📋 Recent logs:"
    tail -15 /tmp/frontend-vite.log
    echo ""
    echo "✅ Frontend restarted successfully!"
    echo "🌐 Access at: https://houseofprayer.ddns.net"
else
    echo "✗ Failed to start"
    echo ""
    echo "❌ Error logs:"
    tail -20 /tmp/frontend-vite.log
    exit 1
fi

echo ""
echo "📝 Full logs: /tmp/frontend-vite.log"
