Skip to content

Instantly share code, notes, and snippets.

@funder7
Last active December 15, 2020 12:38
Show Gist options
  • Save funder7/2aaf64869c0e4e7aaae321546ef4ac0c to your computer and use it in GitHub Desktop.
Save funder7/2aaf64869c0e4e7aaae321546ef4ac0c to your computer and use it in GitHub Desktop.
Starts ngrok, and copies the tunnel hostname into an external file (in this case a spring config). It checks for ngrok executable & configuration file presence.
#!/bin/sh
#
# Wrapper script to launch reverse proxy with local configuration
# and copy tunnel's hostname into (spring) yml configuration
#
# Created 15 december 2020 - Federico Ricchiuto <[email protected]>
#
FILE=./ngrok
CONFIGURATION=./ngrok.yml
SPRING_CONFIG_PATH=~/yourprojectpath/src/main/resources/config/application-dev.yml
OIDC_PROTOCOL='http'
OIDC_PATH='auth/realms/jhipster'
bold=$(tput bold)
echo "Checking ngrok executable..."
if test -f "$FILE"; then
if test -f "$CONFIGURATION"; then
echo "Launching ngrok reverse proxy..."
(./ngrok start -config ./ngrok.yml --all ) > /dev/null &
sleep .7 # Wait for ngrok launch
echo "Getting tunnel hostname..."
NGROK_HOSTNAME=$(curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"https:..([^"]*).*/\1/p')
echo "Replacing backend app IdP setting..."
NEW_SETTING="$OIDC_PROTOCOL://$NGROK_HOSTNAME/$OIDC_PATH"
# macOS only: call sed -i '' -e ... : avoid to create backup file
sed -i -e "s#issuer-uri.*#issuer-uri: ${NEW_SETTING}#" "$SPRING_CONFIG_PATH"
echo "${bold}ngrok running @ $NGROK_HOSTNAME"
wait
else
echo "Missing ngrok.yml configuration file - Pull from repository if deleted"
fi
else
echo "ngrok executable not found"
echo "Download from: https://ngrok.com/download"
fi
@funder7
Copy link
Author

funder7 commented Dec 15, 2020

Configuration file (keep in same folder)

authtoken: xxxxxxx
region: eu
tunnels:
  revproxy:
    addr: 80
    proto: http
    inspect: true

    # enable https only
    # bind_tls: true 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment