@echo off
echo ========================================
echo Starting Backend Server
echo ========================================
echo.

cd /d "%~dp0"

echo Checking if backend is already running...
netstat -ano | findstr :83 >nul
if %errorlevel% == 0 (
    echo ⚠️  Port 83 is already in use!
    echo Killing existing processes...
    for /f "tokens=5" %%a in ('netstat -ano ^| findstr :83 ^| findstr LISTENING') do (
        taskkill /F /PID %%a >nul 2>&1
    )
    timeout /t 2 /nobreak >nul
)

echo.
echo Setting PORT to 83...
set PORT=83

echo.
echo Starting backend server...
echo Backend URL: http://localhost:83
echo Health Check: http://localhost:83/api/health
echo.
echo Press Ctrl+C to stop the server
echo ========================================
echo.

npm start

pause

