#!/usr/bin/env bash
# Serve the bug tracker dashboard on localhost:8089
# Usage: bash projects/msp-tools/bug-tracker/serve.sh [--open]
#
# Pass the Gitea token as ?token=xxx in the browser URL, or set GITEA_TOKEN env var
# to have it injected automatically.

DIR="$(cd "$(dirname "$0")" && pwd)"
PORT=8089

echo "[INFO] Serving bug tracker dashboard at http://localhost:$PORT/dashboard.html"

if [[ -n "$GITEA_TOKEN" ]]; then
  echo "[INFO] Open: http://localhost:$PORT/dashboard.html?token=$GITEA_TOKEN"
else
  echo "[INFO] Add ?token=YOUR_GITEA_TOKEN to the URL for authenticated access"
fi

if [[ "$1" == "--open" ]]; then
  (sleep 1 && start "" "http://localhost:$PORT/dashboard.html") &
fi

cd "$DIR"
python -m http.server $PORT --bind 127.0.0.1
