#!/usr/bin/env bash
# Quick health check for biztaghavi on the server.
# Usage: bash scripts/health-check.sh
set -euo pipefail

APP_DIR="/srv/nodecloud/apps/biztaghavisite"
PORT=3009

echo "=== HTTP Health Check ==="
HTTP_STATUS=$(curl -so /dev/null -w "%{http_code}" --connect-timeout 5 http://127.0.0.1:$PORT/ 2>&1 || echo "FAIL")
if [ "$HTTP_STATUS" = "200" ] || [ "$HTTP_STATUS" = "308" ] || [ "$HTTP_STATUS" = "301" ]; then
  echo "✅ HTTP $HTTP_STATUS — app is responding on port $PORT"
else
  echo "❌ HTTP $HTTP_STATUS — app may be down on port $PORT"
fi

echo ""
echo "=== Container Status ==="
cd "$APP_DIR"
docker compose ps

echo ""
echo "=== Last 20 Log Lines (next-app) ==="
docker compose logs --tail=20 next-app

echo ""
echo "=== Last 10 Log Lines (db) ==="
docker compose logs --tail=10 db
