#!/bin/bash
# Start local HTTP server for site preview
# Usage: tools/check/serve.sh <site-dir> [port]
# Example: tools/check/serve.sh sites/example.com-v1 8080
# Exit codes: 0=success, 2=input error

set -e

SITE_DIR="${1:-.}"
PORT="${2:-8000}"

if [[ ! -d "$SITE_DIR" ]]; then
    echo "ERROR:directory_not_found:$SITE_DIR"
    exit 2
fi

if [[ ! -f "$SITE_DIR/index.html" ]]; then
    echo "WARN:no_index_html:$SITE_DIR"
fi

echo "Starting server for: $(basename "$SITE_DIR")"
echo "URL: http://localhost:$PORT"
echo "Press Ctrl+C to stop"
echo ""

cd "$SITE_DIR"
python3 -m http.server "$PORT"
