2016-06-28 14:43:45 +00:00
|
|
|
#!/bin/sh -e
|
2015-06-22 12:03:40 +00:00
|
|
|
|
2016-06-28 14:43:45 +00:00
|
|
|
if [ -n "$@" ]; then
|
|
|
|
exec "$@"
|
2015-06-22 12:03:40 +00:00
|
|
|
fi
|
|
|
|
|
2016-07-01 14:20:45 +00:00
|
|
|
# Legacy compatible:
|
|
|
|
if [ -z "$NGROK_PORT" ]; then
|
|
|
|
if [ -n "$HTTPS_PORT" ]; then
|
|
|
|
NGROK_PORT="$HTTPS_PORT"
|
|
|
|
elif [ -n "$HTTPS_PORT" ]; then
|
|
|
|
NGROK_PORT="$HTTP_PORT"
|
|
|
|
elif [ -n "$APP_PORT" ]; then
|
|
|
|
NGROK_PORT="$APP_PORT"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2015-06-22 12:03:40 +00:00
|
|
|
|
2016-06-28 14:43:45 +00:00
|
|
|
ARGS="ngrok"
|
2015-06-22 12:03:40 +00:00
|
|
|
|
2016-06-28 14:43:45 +00:00
|
|
|
# Set the protocol.
|
|
|
|
if [ "$NGROK_PROTOCOL" = "TCP" ]; then
|
|
|
|
ARGS="$ARGS tcp"
|
|
|
|
else
|
|
|
|
ARGS="$ARGS http"
|
2016-07-01 14:20:45 +00:00
|
|
|
NGROK_PORT="${NGROK_PORT:-80}"
|
2016-06-28 14:43:45 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Set the authorization token.
|
2015-06-22 12:03:40 +00:00
|
|
|
if [ -n "$NGROK_AUTH" ]; then
|
2016-06-28 14:43:45 +00:00
|
|
|
ARGS="$ARGS -authtoken=$NGROK_AUTH "
|
2015-06-22 12:03:40 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Set the subdomain or hostname, depending on which is set
|
|
|
|
if [ -n "$NGROK_HOSTNAME" ] && [ -n "$NGROK_AUTH" ]; then
|
|
|
|
ARGS="$ARGS -hostname=$NGROK_HOSTNAME "
|
|
|
|
elif [ -n "$NGROK_SUBDOMAIN" ] && [ -n "$NGROK_AUTH" ]; then
|
|
|
|
ARGS="$ARGS -subdomain=$NGROK_SUBDOMAIN "
|
|
|
|
elif [ -n "$NGROK_HOSTNAME" ] || [ -n "$NGROK_SUBDOMAIN" ]; then
|
|
|
|
if [ -z "$NGROK_AUTH" ]; then
|
2016-06-28 14:58:56 +00:00
|
|
|
echo "You must specify an authentication token after registering at https://ngrok.com to use custom domains."
|
2015-06-22 12:03:40 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2016-10-17 10:12:09 +00:00
|
|
|
# Set a custom region
|
|
|
|
if [ -n "$NGROK_REGION" ]; then
|
|
|
|
ARGS="$ARGS -region=$NGROK_REGION "
|
|
|
|
fi
|
|
|
|
|
2015-06-22 12:03:40 +00:00
|
|
|
if [ -n "$NGROK_HEADER" ]; then
|
|
|
|
ARGS="$ARGS -host-header=$NGROK_HEADER "
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$NGROK_USERNAME" ] && [ -n "$NGROK_PASSWORD" ] && [ -n "$NGROK_AUTH" ]; then
|
2018-08-07 20:26:37 +00:00
|
|
|
ARGS="$ARGS -auth=$NGROK_USERNAME:$NGROK_PASSWORD "
|
2015-06-22 12:03:40 +00:00
|
|
|
elif [ -n "$NGROK_USERNAME" ] || [ -n "$NGROK_PASSWORD" ]; then
|
|
|
|
if [ -z "$NGROK_AUTH" ]; then
|
2016-06-28 14:43:45 +00:00
|
|
|
echo "You must specify a username, password, and Ngrok authentication token to use the custom HTTP authentication."
|
2015-06-22 12:03:40 +00:00
|
|
|
echo "Sign up for an authentication token at https://ngrok.com"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-05-18 07:58:00 +00:00
|
|
|
if [ -n "$NGROK_DEBUG" ]; then
|
|
|
|
ARGS="$ARGS -log stdout"
|
|
|
|
fi
|
2016-06-28 14:43:45 +00:00
|
|
|
|
2016-07-01 14:20:45 +00:00
|
|
|
# Set the port.
|
|
|
|
if [ -z "$NGROK_PORT" ]; then
|
|
|
|
echo "You must specify a NGROK_PORT to expose."
|
|
|
|
exit 1
|
2016-06-28 14:43:45 +00:00
|
|
|
fi
|
2016-07-01 14:20:45 +00:00
|
|
|
ARGS="$ARGS `echo $NGROK_PORT | sed 's|^tcp://||'`"
|
2015-06-22 12:03:40 +00:00
|
|
|
|
2016-06-28 14:43:45 +00:00
|
|
|
set -x
|
|
|
|
exec $ARGS
|