@echo off
echo ========================================
echo Starting Navy CMS Backend Server
echo Port: 83
echo ========================================
echo.

cd /d "%~dp0"

echo Checking if dist folder exists...
if not exist "dist\server.js" (
    echo dist\server.js not found. Building backend...
    call npm run build
    if errorlevel 1 (
        echo Build failed! Trying dev mode instead...
        echo.
        echo Starting in development mode...
        set PORT=83
        call npm run dev
        exit /b
    )
)

echo.
echo 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

