#!/bin/bash
# Quick verification that fixes are applied

echo "🔍 Verifying Fixes Applied"
echo "=========================="
echo ""

# Check 1: Auth middleware format
echo -n "1. Auth middleware (CommonJS format)... "
if grep -q "module.exports" /media/pts/Website/Church_HOP_MusicData/new-site/backend/middleware/auth.js; then
    echo "✅ FIXED"
else
    echo "❌ NOT FIXED"
fi

# Check 2: Vite HMR config
echo -n "2. Vite HMR configuration............ "
if grep -q "hmr:" /media/pts/Website/Church_HOP_MusicData/new-site/frontend/vite.config.js; then
    echo "✅ FIXED"
else
    echo "❌ NOT FIXED"
fi

# Check 3: Nginx CORS handling
echo -n "3. Nginx CORS preflight.............. "
if grep -q "OPTIONS" /media/pts/Website/Church_HOP_MusicData/new-site/nginx-ssl.conf; then
    echo "✅ FIXED"
else
    echo "❌ NOT FIXED"
fi

# Check 4: Nginx WebSocket support
echo -n "4. Nginx WebSocket buffering......... "
if grep -q "proxy_buffering off" /media/pts/Website/Church_HOP_MusicData/new-site/nginx-ssl.conf; then
    echo "✅ FIXED"
else
    echo "❌ NOT FIXED"
fi

echo ""
echo "=========================="
echo ""

# Check running services
echo "🔄 Service Status:"
echo "------------------"

echo -n "Backend (port 8080)...... "
if netstat -tln 2>/dev/null | grep -q ":8080 " || ss -tln 2>/dev/null | grep -q ":8080 "; then
    echo "✅ RUNNING"
else
    echo "❌ NOT RUNNING"
fi

echo -n "Frontend (port 5100)..... "
if netstat -tln 2>/dev/null | grep -q ":5100 " || ss -tln 2>/dev/null | grep -q ":5100 "; then
    echo "✅ RUNNING"
else
    echo "⚠️  NOT RUNNING (needs restart)"
fi

echo -n "Nginx (port 443)......... "
if netstat -tln 2>/dev/null | grep -q ":443 " || ss -tln 2>/dev/null | grep -q ":443 "; then
    echo "✅ RUNNING"
else
    echo "❌ NOT RUNNING"
fi

echo ""
echo "=========================="
echo ""
echo "📝 Next Steps:"
echo "1. Restart frontend: bash restart-frontend.sh"
echo "2. Copy Nginx config: sudo cp nginx-ssl.conf /etc/nginx/sites-available/church-music-ssl.conf"
echo "3. Reload Nginx: sudo systemctl reload nginx"
echo "4. Test site: https://houseofprayer.ddns.net"
echo ""
