This commit is contained in:
丹尼尔
2026-03-12 11:52:04 +08:00
parent 30a57d993c
commit bdba4ec071
19 changed files with 5690 additions and 191 deletions

View File

@@ -17,10 +17,10 @@ rm -f "$NGROK_LOG"
if curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:4040/api/tunnels 2>/dev/null | grep -q 200; then
echo "检测到 ngrok 已在运行4040 可访问),直接读取 URL..."
else
echo "启动 ngrok http 8000后端需在 8000 端口,可先在本脚本之后另开终端运行 ./run-dev.sh..."
echo "启动 ngrok http 8000后端需在 8000 端口)..."
nohup ngrok http 8000 --log=stdout > "$NGROK_LOG" 2>&1 &
NGROK_PID=$!
echo "等待 ngrok 就绪(最多 30 秒,并从日志解析 URL..."
echo "等待 ngrok 就绪(最多 30 秒)..."
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30; do
if curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:4040/api/tunnels 2>/dev/null | grep -q 200; then
break
@@ -73,11 +73,9 @@ import sys, json
try:
d = json.load(sys.stdin)
tunnels = d.get('tunnels') if isinstance(d, dict) else (d if isinstance(d, list) else [])
if not isinstance(tunnels, list):
tunnels = []
if not isinstance(tunnels, list): tunnels = []
for t in tunnels:
if not isinstance(t, dict):
continue
if not isinstance(t, dict): continue
u = (t.get('public_url') or t.get('PublicURL') or '').strip()
if u.startswith('https://'):
print(u.rstrip('/'))
@@ -85,17 +83,11 @@ try:
else:
if tunnels:
u = (tunnels[0].get('public_url') or tunnels[0].get('PublicURL') or '').strip()
if u:
print(u.rstrip('/'))
except Exception:
pass
if u: print(u.rstrip('/'))
except Exception: pass
" 2>/dev/null)
if [ -z "$PUBLIC_URL" ]; then
PUBLIC_URL=$(echo "$PAYLOAD" | grep -oE 'https://[a-zA-Z0-9][-a-zA-Z0-9.]*\.(ngrok-free\.app|ngrok\.io|ngrok-app\.com)[^"]*' | head -1 | sed 's|"$||')
fi
if [ -z "$PUBLIC_URL" ]; then
PUBLIC_URL=$(echo "$PAYLOAD" | grep -oE '"public_url"\s*:\s*"https://[^"]+' | sed 's/.*"https:/https:/' | sed 's/"$//' | head -1)
fi
[ -z "$PUBLIC_URL" ] && PUBLIC_URL=$(echo "$PAYLOAD" | grep -oE 'https://[a-zA-Z0-9][-a-zA-Z0-9.]*\.(ngrok-free\.app|ngrok\.io|ngrok-app\.com)[^"]*' | head -1 | sed 's|"$||')
[ -z "$PUBLIC_URL" ] && PUBLIC_URL=$(echo "$PAYLOAD" | grep -oE '"public_url"\s*:\s*"https://[^"]+' | sed 's/.*"https:/https:/' | sed 's/"$//' | head -1)
fi
if [ -z "$PUBLIC_URL" ]; then