#!/bin/bash
# 启动 Cloudflare Tunnel（替代 ngrok，无警告页面）
#
# 使用方法：
#   ./start-tunnel.sh
#
# 会输出一个 URL，类似：
#   https://xxx-xxx-xxx.trycloudflare.com
#
# 把这个 URL 复制到 .env 文件的 TUNNEL_URL 配置中

echo "🚀 启动 Cloudflare Tunnel..."
echo ""
echo "等待隧道建立，会显示一个 trycloudflare.com 的 URL"
echo "请复制该 URL 到 .env 文件的 TUNNEL_URL 配置中"
echo ""
echo "按 Ctrl+C 停止隧道"
echo ""

# 检查 cloudflared 是否安装
if ! command -v cloudflared &> /dev/null; then
    echo "❌ cloudflared 未安装"
    echo ""
    echo "请先安装 cloudflared:"
    echo "  macOS:   brew install cloudflared"
    echo "  Linux:   curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o cloudflared && chmod +x cloudflared && sudo mv cloudflared /usr/local/bin/"
    echo "  Windows: 从 https://github.com/cloudflare/cloudflared/releases 下载"
    exit 1
fi

# 启动隧道
cloudflared tunnel --url http://localhost:8000
