PMFlow/devops/tunnel/start-quick.sh

68 lines
2.1 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.

#!/bin/bash
# Cloudflare Quick Tunnel (No Domain Required)
# Generates a random stable-ish URL for the session
echo "🚀 Starting Quick Tunnel..."
echo "⚠️ Note: This uses a random trycloudflare.com URL."
echo "⚠️ For a fixed custom domain, you must PURCHASE a domain and configure it via setup.sh"
# Kill existing tunnels
pkill -f "cloudflared tunnel" >/dev/null 2>&1 || true
echo "🌐 Starting Frontend Tunnel (port 5174)..."
cloudflared tunnel --url http://localhost:5174 > logs/tunnel-frontend.log 2>&1 &
PID_FRONT=$!
echo "🌐 Starting Backend Tunnel (port 8000)..."
cloudflared tunnel --url http://localhost:8000 > logs/tunnel-backend.log 2>&1 &
PID_BACK=$!
echo "⏳ Waiting for tunnels to initialize..."
sleep 5
URL_FRONT=$(grep -o 'https://.*\.trycloudflare.com' logs/tunnel-frontend.log | head -1)
URL_BACK=$(grep -o 'https://.*\.trycloudflare.com' logs/tunnel-backend.log | head -1)
check_url() {
local url="$1"
local max_retry="$2"
local retry=1
while [ "$retry" -le "$max_retry" ]; do
if curl -kfsS --max-time 8 "$url" >/dev/null 2>&1; then
return 0
fi
sleep 2
retry=$((retry + 1))
done
return 1
}
if [ -n "$URL_FRONT" ] && [ -n "$URL_BACK" ]; then
FRONT_OK=false
BACK_OK=false
if check_url "${URL_FRONT}/login" 25 || check_url "${URL_FRONT}" 25; then
FRONT_OK=true
fi
if check_url "${URL_BACK}/healthz" 25; then
BACK_OK=true
fi
echo ""
if [ "$FRONT_OK" = true ] && [ "$BACK_OK" = true ]; then
echo "✅ Tunnels Started and reachable!"
else
echo "⚠️ Tunnels started, but health check not fully ready yet. Retry in 10-30s."
fi
echo "----------------------------------------"
echo "Frontend: $URL_FRONT"
echo "Backend: $URL_BACK"
echo "----------------------------------------"
echo "ℹ️ Frontend tunnel can call backend via /api proxy; no need to set VITE_API_BASE_URL."
echo "----------------------------------------"
else
echo "❌ Failed to get tunnel URLs. Check logs/tunnel-*.log"
fi
wait $PID_FRONT $PID_BACK