@echo off
REM Test No-IP Configuration
REM This script tests if your No-IP setup is working

echo ========================================
echo NO-IP CONFIGURATION TEST
echo ========================================
echo.
echo Domain: houseofprayer.ddns.net
echo.

echo [1/5] Testing DNS Resolution...
echo.
nslookup houseofprayer.ddns.net
if %errorlevel% equ 0 (
    echo [OK] DNS resolves correctly
) else (
    echo [ERROR] DNS resolution failed
    echo Make sure No-IP DUC is running and up to date
)
echo.
echo ========================================
echo.

echo [2/5] Checking if backend is running locally...
echo.
curl -s http://localhost:5000/api/health > nul 2>&1
if %errorlevel% equ 0 (
    echo [OK] Backend running on localhost:5000
    curl http://localhost:5000/api/health
) else (
    echo [ERROR] Backend not running
    echo Start the backend server first: start-backend.bat
)
echo.
echo ========================================
echo.

echo [3/5] Checking if frontend is running locally...
echo.
curl -s http://localhost:3000 > nul 2>&1
if %errorlevel% equ 0 (
    echo [OK] Frontend running on localhost:3000
) else (
    echo [WARNING] Frontend not detected
    echo Start the frontend server: start-frontend.bat
)
echo.
echo ========================================
echo.

echo [4/5] Checking listening ports...
echo.
netstat -an | findstr ":5000"
netstat -an | findstr ":3000"
if %errorlevel% equ 0 (
    echo [OK] Servers are listening on required ports
) else (
    echo [WARNING] Servers may not be listening
)
echo.
echo ========================================
echo.

echo [5/5] Testing external backend access...
echo.
echo Attempting to connect to: http://houseofprayer.ddns.net:5000/api/health
echo.
curl -s --connect-timeout 5 http://houseofprayer.ddns.net:5000/api/health
if %errorlevel% equ 0 (
    echo.
    echo [OK] External access working!
    echo Your No-IP setup is complete and working
) else (
    echo.
    echo [ERROR] Cannot connect externally
    echo.
    echo Possible issues:
    echo 1. Router port forwarding not configured
    echo 2. Windows Firewall blocking connections
    echo 3. No-IP DUC not running or not updated
    echo 4. ISP blocking the port
    echo.
    echo To test from outside your network:
    echo - Use phone with mobile data (WiFi off)
    echo - Visit: http://houseofprayer.ddns.net:5000/api/health
)
echo.
echo ========================================
echo.

echo Test Summary:
echo - DNS Resolution: Check above
echo - Local Backend: Check above
echo - Local Frontend: Check above
echo - Port Listening: Check above
echo - External Access: Check above
echo.
echo Next Steps:
echo 1. If DNS fails: Check No-IP DUC is running
echo 2. If local fails: Start the servers
echo 3. If external fails: Configure router port forwarding
echo 4. If still fails: Run configure-firewall.bat as admin
echo.
echo For detailed troubleshooting, see: NOIP_SETUP_GUIDE.md
echo.
pause
