entrypoint.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. if [ -n "$NGROK_DEBUG" ]; then
  55. ARGS="$ARGS -log stdout"
  56. fi
  57. # Set the port.
  58. if [ -z "$NGROK_PORT" ]; then
  59. echo "You must specify a NGROK_PORT to expose."
  60. exit 1
  61. fi
  62. ARGS="$ARGS `echo $NGROK_PORT | sed 's|^tcp://||'`"
  63. set -x
  64. exec $ARGS