diff --git a/bin/_helpers b/bin/_helpers index 33caa48..e0bd47b 100644 --- a/bin/_helpers +++ b/bin/_helpers @@ -94,6 +94,10 @@ function output_info { output_tagged_string "$BG_B" "INFO" "$1" } +function output_warning { + output_tagged_string "$BG_Y" "WARNING" "$1" +} + export BG_R export BG_G export BG_Y diff --git a/bin/proxy b/bin/proxy index f1015ba..98ea3b3 100755 --- a/bin/proxy +++ b/bin/proxy @@ -1,5 +1,16 @@ #!/usr/bin/env bash +# Enable auto-export +set -a + +if [ -f ".env" ]; then + # shellcheck source=/dev/null + source ".env" +fi + +# Disable auto-export +set +a + HOP_PATH=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) TOOLKIT_PATH=$(dirname "$HOP_PATH") @@ -147,6 +158,16 @@ function pick_one_virtual_host_from_file() { HOST_STRING=$(sed -nr 's/.*VIRTUAL_HOST=(.*)/\1/p' "$FILE") + # Trim double quotes from HOST_STRING + HOST_STRING=$(echo "$HOST_STRING" | tr -d '"') + + # Pipe HOST_STRING through envsubst if available + if command -v envsubst &> /dev/null; then + HOST_STRING=$(echo "$HOST_STRING" | envsubst) + else + >&2 output_warning "envsubst not found. Skipping environment variable substitution." + fi + IFS="," read -ra HOSTS <<< "$HOST_STRING" for HOST_ENTRY in "${HOSTS[@]}"; do