@echo off
echo ========================================
echo Restarting Navy CMS Backend Server
echo ========================================
echo.

cd /d "%~dp0"

echo Step 1: Stopping any running backend processes...
taskkill /F /IM node.exe /FI "WINDOWTITLE eq *backend*" 2>nul
timeout /t 2 /nobreak >nul

echo.
echo Step 2: Building backend...
call npm run build
if errorlevel 1 (
    echo Build failed!
    pause
    exit /b 1
)

echo.
echo Step 3: Starting backend server on port 83...
echo Backend will be available at: http://localhost:83
echo API Health Check: http://localhost:83/api/health
echo.
echo Press Ctrl+C to stop the server
echo.

set PORT=83
call npm start

pause
