Files
wecom-ai-assistant/setup-cloudflared.ps1
2026-02-05 16:36:32 +08:00

67 lines
2.8 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Cloudflare Tunnel 安装和启动脚本
Write-Host "=== Cloudflare Tunnel 设置 ===" -ForegroundColor Cyan
# 检查是否已安装
$cloudflaredPath = Get-Command cloudflared -ErrorAction SilentlyContinue
if (-not $cloudflaredPath) {
Write-Host "`n[1/4] cloudflared 未安装,开始安装..." -ForegroundColor Yellow
# 检查是否有 Scoop
$scoopPath = Get-Command scoop -ErrorAction SilentlyContinue
if ($scoopPath) {
Write-Host "检测到 Scoop使用 Scoop 安装..." -ForegroundColor Green
scoop install cloudflared
} else {
Write-Host "未检测到 Scoop请手动安装 cloudflared" -ForegroundColor Yellow
Write-Host "1. 下载https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.msi" -ForegroundColor Cyan
Write-Host "2. 双击安装 MSI 文件" -ForegroundColor Cyan
Write-Host "3. 重新运行此脚本" -ForegroundColor Cyan
exit 1
}
} else {
Write-Host "`n[1/4] ✓ cloudflared 已安装" -ForegroundColor Green
cloudflared --version
}
# 检查 Docker 服务
Write-Host "`n[2/4] 检查 Docker 服务..." -ForegroundColor Yellow
$backendStatus = docker compose ps backend --format json | ConvertFrom-Json | Select-Object -ExpandProperty State
if ($backendStatus -ne "running") {
Write-Host "后端服务未运行,正在启动..." -ForegroundColor Yellow
docker compose up -d backend
Start-Sleep -Seconds 5
}
Write-Host "✓ Docker 服务运行正常" -ForegroundColor Green
# 测试本地服务
Write-Host "`n[3/4] 测试本地服务..." -ForegroundColor Yellow
try {
$response = Invoke-WebRequest -Uri "http://localhost:8000/api/health" -UseBasicParsing -TimeoutSec 5
if ($response.StatusCode -eq 200) {
Write-Host "✓ 本地服务正常 (http://localhost:8000)" -ForegroundColor Green
}
} catch {
Write-Host "✗ 本地服务无法访问,请检查后端服务" -ForegroundColor Red
Write-Host "运行: docker compose logs backend" -ForegroundColor Yellow
exit 1
}
# 启动 cloudflared
Write-Host "`n[4/4] 启动 Cloudflare Tunnel..." -ForegroundColor Yellow
Write-Host "正在启动 tunnel请稍候..." -ForegroundColor Cyan
Write-Host "`n=== 重要提示 ===" -ForegroundColor Yellow
Write-Host "1. 下方会显示公网 URL例如https://xxx.trycloudflare.com" -ForegroundColor White
Write-Host "2. 复制这个 URL用于配置企业微信回调" -ForegroundColor White
Write-Host "3. 回调 URL 格式https://你的域名.trycloudflare.com/api/wecom/callback" -ForegroundColor White
Write-Host "4. 保持此窗口运行,不要关闭" -ForegroundColor White
Write-Host "`n按 Ctrl+C 停止 tunnel`n" -ForegroundColor Yellow
Write-Host "=" * 60 -ForegroundColor Cyan
# 启动 tunnel
cloudflared tunnel --url http://localhost:8000