diff --git a/dev-proxy.sh b/dev-proxy.sh index 754a451..29b627d 100755 --- a/dev-proxy.sh +++ b/dev-proxy.sh @@ -1,9 +1,27 @@ #!/bin/bash DOMAIN=$1 -TARGET=$2 +TARGET_RAW=$2 PATTERNS=$3 REAL_IP_OVERRIDE=$4 HOSTS_LINE="127.0.0.1 $DOMAIN" + +# Parse TARGET: support both host:port and full URLs (http:// or https://) +if [[ "$TARGET_RAW" =~ ^https?:// ]]; then + TARGET_SCHEME=$(echo "$TARGET_RAW" | sed -E 's|^(https?)://.*|\1|') + TARGET_HOST=$(echo "$TARGET_RAW" | sed -E 's|^https?://([^/:]+).*|\1|') + TARGET_PORT=$(echo "$TARGET_RAW" | sed -E 's|^https?://[^/:]+:?([0-9]*)/?\s*$|\1|') + if [ -z "$TARGET_PORT" ]; then + if [ "$TARGET_SCHEME" = "https" ]; then + TARGET_PORT=443 + else + TARGET_PORT=80 + fi + fi + TARGET="${TARGET_HOST}:${TARGET_PORT}" +else + TARGET_SCHEME="http" + TARGET="$TARGET_RAW" +fi NGINX_CONF=$(mktemp) CERT_DIR=$(pwd) CLEANUP_DONE=0 @@ -73,28 +91,46 @@ if [ -n "$PATTERNS" ]; then done fi -cat > "$NGINX_CONF" < "$NGINX_CONF" <