#!/bin/bash

echo "🚀 启动 HTTP 服务器..."

# 确保在正确的目录中
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"

echo "📂 当前目录: $SCRIPT_DIR"

# 获取本机IP地址
SERVER_IP=$(hostname -I | awk '{print $1}')
echo "🌐 本机 IP 地址: $SERVER_IP"

# 检查Python是否可用
if command -v python3 &> /dev/null; then
    PYTHON_CMD="python3"
elif command -v python &> /dev/null; then
    PYTHON_CMD="python"
else
    echo "❌ 错误: 未找到 Python"
    echo "请安装 Python 或手动打开文件"
    exit 1
fi

echo ""
echo "📱 访问地址:"
echo "   - 主页: http://$SERVER_IP:8000/pages/main.html"
echo "   - 登录: http://$SERVER_IP:8000/pages/login.html"
echo ""
echo "⚠️  服务器将在端口 8000 启动"
echo "按 Ctrl+C 停止服务器"
echo ""

# 启动HTTP服务器
$PYTHON_CMD -m http.server 8000
