From 87ca4fdcc574c2d9e0094238826e8a72071ee9af Mon Sep 17 00:00:00 2001 From: Michael Mendy Date: Tue, 25 Feb 2025 14:03:45 -0800 Subject: [PATCH] add configurable port and better error handling --- tunnel.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tunnel.sh b/tunnel.sh index 41f7402..07d3ada 100755 --- a/tunnel.sh +++ b/tunnel.sh @@ -1,13 +1,25 @@ #!/bin/sh +if [ "$1" = "--help" ]; then + echo "Usage: $0 [domain]" + echo "Exposes local server on port \$PORT (default 3040) via ngrok." + echo "If domain is provided, uses that domain." + exit 0 +fi + domain=$1 -port=3040 +port=${PORT:-3040} if ! command -v ngrok >/dev/null 2>&1; then echo "Please install ngrok: https://ngrok.com/download" exit 1 fi +if ! nc -z localhost "$port" > /dev/null 2>&1; then + echo "Warning: No server is listening on port $port. Ngrok might not work as expected." +fi + +echo "Starting ngrok on port $port..." if [ -n "$domain" ]; then ngrok http --domain="$domain" "$port" else