Giter Club home page Giter Club logo

Comments (5)

jarkt avatar jarkt commented on August 15, 2024

Oh there it is, just slipped while reading. :-)
curl $(docker port www_ngrok 4040)/api/tunnels

from docker-ngrok.

guicara avatar guicara commented on August 15, 2024

And if you want to extract directly the URL from the JSON, you can use this script:

curl -s $(docker port www_ngrok 4040)/api/tunnels/command_line | grep -o '"public_url": *"[^"]*"' | grep -o '"[^"]*"$' | sed -e 's/^"//' -e 's/"$//'

from docker-ngrok.

jarkt avatar jarkt commented on August 15, 2024

Parsing JSON with jq is much more readable.
I use it in a docker environment and need the url in the webserver container.
The webserver container has an entrypoint.sh, looking like this:

echo Get ngrok tunnel url...
export WEBHOOK_BASE_URL=$(bash /scripts/ngrok_url.sh)

echo Start webserver...
apache2-foreground

In ngrok_url.sh I have to wait that I can retrieve the url:

function echoUrl {
  ngrok_tunnels=$(curl -s http://ngrok:4040/api/tunnels)
  index=$(echo $ngrok_tunnels | jq '.tunnels | map(.proto == "https") | index(true)')
  echo $ngrok_tunnels | jq -r ".tunnels[$index].public_url"
}

n=0
until [ "$n" -ge 5 ]
do
  echoUrl && break
  n=$((n+1))
  sleep 5
done

from docker-ngrok.

guicara avatar guicara commented on August 15, 2024

I agree with you, jq is more readable.

However, jq is not always available by default on all distros. This is why I've used grep and sed instead. Telling my team to install an additional package was not an option for me.

from docker-ngrok.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.