Last active
December 15, 2020 12:38
-
-
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.
This file contains 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 | |
# | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Configuration file (keep in same folder)