Created
December 25, 2024 05:47
-
-
Save cyai/ccfea98d991ed100923a0708b221bb62 to your computer and use it in GitHub Desktop.
Run ngrok tcp connection in background and get the public url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
LOCAL_PORT=${1-10000} | |
echo "Starting ngrok in the background on TCP port [ $LOCAL_PORT ]" | |
nohup ngrok tcp ${LOCAL_PORT} &>/dev/null & | |
echo -n "Extracting ngrok public URL for TCP ." | |
NGROK_PUBLIC_URL="" | |
while [ -z "$NGROK_PUBLIC_URL" ]; do | |
# Run 'curl' against ngrok API and extract public URL for TCP using 'sed' | |
export NGROK_PUBLIC_URL=$(curl --silent --max-time 10 --connect-timeout 5 \ | |
--show-error http://127.0.0.1:4040/api/tunnels | \ | |
sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p') | |
sleep 1 | |
echo -n "." | |
done | |
echo | |
echo "NGROK_PUBLIC_URL => [ tcp://$NGROK_PUBLIC_URL ]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment