/ docker / cloudflared-entrypoint.sh
cloudflared-entrypoint.sh
 1  #!/bin/sh
 2  
 3  if [ -n "$WAVE_PUBLIC_URL" ]; then
 4    echo "WAVE_PUBLIC_URL is set to '$WAVE_PUBLIC_URL'. Skipping Cloudflare Tunnel startup."
 5    touch /tmp/tunnel/ready
 6    while true; do
 7      touch /tmp/tunnel/ready
 8      sleep 5
 9    done
10  fi
11  
12  mkdir -p /tmp/tunnel
13  rm -f /tmp/tunnel/url.txt
14  rm -f /tmp/tunnel/tunnel.log
15  rm -f /tmp/tunnel/ready
16  
17    echo "Starting Quick Tunnel..."
18    # Run cloudflared in background, piping logs to file
19    cloudflared tunnel --url http://wave:8000 2>&1 | tee /tmp/tunnel/tunnel.log &
20    PID=$!
21    # Wait for URL to appear in logs
22    echo "Waiting for URL..."
23    (
24      while true; do
25        if grep -o 'https://[-a-z0-9.]*\.trycloudflare\.com' /tmp/tunnel/tunnel.log | head -n 1 > /tmp/tunnel/url.tmp && [ -s /tmp/tunnel/url.tmp ]; then
26          mv /tmp/tunnel/url.tmp /tmp/tunnel/url.txt
27          touch /tmp/tunnel/ready
28          echo "URL captured: $(cat /tmp/tunnel/url.txt)"
29          # Keep ready file fresh
30          while true; do
31            sleep 5
32            touch /tmp/tunnel/ready
33          done
34          break
35        fi
36        sleep 1
37      done
38    ) &
39    wait $PID