Files
wechatAiclaw/run.sh
丹尼尔 8b62c445fc fix:bug
2026-03-12 18:42:23 +08:00

65 lines
2.2 KiB
Bash
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.
#!/usr/bin/env bash
# 统一启动:可选代理桥接 → ngrok 暴露回调 → 后端+前端
set -e
cd "$(dirname "$0")"
# 用法
usage() {
echo "用法: ./run.sh [--proxy-bridge]"
echo " --proxy-bridge 先启动本地代理桥接(8899→127.0.0.1:7890),便于 7006 通过 ngrok 使用本机代理"
echo "无参数时仅: ngrok 暴露 8000 并写入 CALLBACK_BASE_URL → 启动 run-dev.sh"
echo " .env 中已有 CALLBACK_BASE_URL 时不会覆盖,重启无需重设;换 ngrok 地址后执行: ./run-ngrok.sh --update"
echo ""
echo "注意: ngrok 免费版仅 1 个隧道,已用于 8000回调代理需另开隧道或 cloudflared 暴露 8899 后填 .env。"
}
USE_PROXY_BRIDGE=0
for arg in "$@"; do
case "$arg" in
-h|--help) usage; exit 0 ;;
--proxy-bridge) USE_PROXY_BRIDGE=1 ;;
esac
done
# 可选启动本地代理桥接8899 → 127.0.0.1:7890
if [ "$USE_PROXY_BRIDGE" = "1" ]; then
if [ ! -f "scripts/local_proxy_bridge.py" ]; then
echo "未找到 scripts/local_proxy_bridge.py跳过代理桥接"
else
PYTHON="python3"
if [ -d ".venv" ]; then
PYTHON=".venv/bin/python"
fi
if ! lsof -i :8899 >/dev/null 2>&1; then
echo "启动本地代理桥接 :8899 → 127.0.0.1:7890 ..."
nohup "$PYTHON" scripts/local_proxy_bridge.py >> /tmp/proxy-bridge.log 2>&1 &
echo $! > /tmp/proxy-bridge.pid
sleep 1
echo " 已启动。若需 7006 走本机代理,需另用 ngrok 付费多隧道或 cloudflared 暴露 8899将 URL 填入 .env 的 HTTP_PROXY。"
else
echo "端口 8899 已被占用,跳过代理桥接(可能已在运行)"
fi
fi
fi
# 退出时清理本脚本启动的代理桥接
cleanup_proxy_bridge() {
if [ -f /tmp/proxy-bridge.pid ]; then
PID=$(cat /tmp/proxy-bridge.pid 2>/dev/null)
if [ -n "$PID" ] && kill -0 "$PID" 2>/dev/null; then
kill "$PID" 2>/dev/null || true
echo "已停止代理桥接 (PID $PID)"
fi
rm -f /tmp/proxy-bridge.pid
fi
}
trap cleanup_proxy_bridge EXIT
# 1) ngrok 暴露 8000写入 .env 的 CALLBACK_BASE_URL
echo ">>> 配置 ngrok 回调地址..."
sh ./run-ngrok.sh
# 2) 启动后端 + 前端run-dev.sh
echo ">>> 启动后端与前端..."
sh ./run-dev.sh