entrypoint.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/sh -e
  2. if [ -n "$@" ]; then
  3. exec "$@"
  4. fi
  5. # Legacy compatible:
  6. if [ -z "$NGROK_PORT" ]; then
  7. if [ -n "$HTTPS_PORT" ]; then
  8. NGROK_PORT="$HTTPS_PORT"
  9. elif [ -n "$HTTPS_PORT" ]; then
  10. NGROK_PORT="$HTTP_PORT"
  11. elif [ -n "$APP_PORT" ]; then
  12. NGROK_PORT="$APP_PORT"
  13. fi
  14. fi
  15. ARGS="ngrok"
  16. # Set the protocol.
  17. if [ "$NGROK_PROTOCOL" = "TCP" ]; then
  18. ARGS="$ARGS tcp"
  19. else
  20. ARGS="$ARGS http"
  21. NGROK_PORT="${NGROK_PORT:-80}"
  22. fi
  23. # Set the authorization token.
  24. if [ -n "$NGROK_AUTH" ]; then
  25. ARGS="$ARGS -authtoken=$NGROK_AUTH "
  26. fi
  27. # Set the subdomain or hostname, depending on which is set
  28. if [ -n "$NGROK_HOSTNAME" ] && [ -n "$NGROK_AUTH" ]; then
  29. ARGS="$ARGS -hostname=$NGROK_HOSTNAME "
  30. elif [ -n "$NGROK_SUBDOMAIN" ] && [ -n "$NGROK_AUTH" ]; then
  31. ARGS="$ARGS -subdomain=$NGROK_SUBDOMAIN "
  32. elif [ -n "$NGROK_HOSTNAME" ] || [ -n "$NGROK_SUBDOMAIN" ]; then
  33. if [ -z "$NGROK_AUTH" ]; then
  34. echo "You must specify an authentication token after registering at https://ngrok.com to use custom domains."
  35. exit 1
  36. fi
  37. fi
  38. # Set a custom region
  39. if [ -n "$NGROK_REGION" ]; then
  40. ARGS="$ARGS -region=$NGROK_REGION "
  41. fi
  42. if [ -n "$NGROK_HEADER" ]; then
  43. ARGS="$ARGS -host-header=$NGROK_HEADER "
  44. fi
  45. if [ -n "$NGROK_USERNAME" ] && [ -n "$NGROK_PASSWORD" ] && [ -n "$NGROK_AUTH" ]; then
  46. ARGS="$ARGS -auth=\"$NGROK_USERNAME:$NGROK_PASSWORD\" "
  47. elif [ -n "$NGROK_USERNAME" ] || [ -n "$NGROK_PASSWORD" ]; then
  48. if [ -z "$NGROK_AUTH" ]; then
  49. echo "You must specify a username, password, and Ngrok authentication token to use the custom HTTP authentication."
  50. echo "Sign up for an authentication token at https://ngrok.com"
  51. exit 1
  52. fi
  53. fi
  54. ARGS="$ARGS -log stdout"
  55. # Set the port.
  56. if [ -z "$NGROK_PORT" ]; then
  57. echo "You must specify a NGROK_PORT to expose."
  58. exit 1
  59. fi
  60. ARGS="$ARGS `echo $NGROK_PORT | sed 's|^tcp://||'`"
  61. set -x
  62. exec $ARGS