@echo off
REM ============================================================
REM  Radio TordenSkrall Chat - lokal server (dobbeltklikk for aa starte)
REM ============================================================
title Radio TordenSkrall Chat  - lokal server
cd /d "%~dp0"

echo.
echo  ===============================================
echo   Radio TordenSkrall Chat - starter lokal server...
echo  ===============================================
echo.

REM --- Sjekk at Node.js finnes ---
where node >nul 2>nul
if errorlevel 1 (
  echo  [FEIL] Node.js er ikke installert eller ikke i PATH.
  echo  Last ned og installer fra: https://nodejs.org/
  echo.
  pause
  exit /b 1
)

REM --- Installer avhengigheter forste gang ---
if not exist "node_modules" (
  echo  Forste gangs oppstart - installerer avhengigheter...
  call npm install
  if errorlevel 1 (
    echo  [FEIL] npm install feilet.
    pause
    exit /b 1
  )
)

REM --- Aapne nettleseren etter at serveren har startet ---
start "" cmd /c "timeout /t 2 >nul & start http://localhost:3000"

echo.
echo  Serveren kjorer paa: http://localhost:3000
echo  Admin-panel:         http://localhost:3000/admin
echo.
echo  Lukk dette vinduet (eller trykk Ctrl+C) for aa stoppe serveren.
echo.

node server.js

echo.
echo  Serveren ble stoppet.
pause
