gstaff / flask-ngrok

A simple way to demo Flask apps from your machine.
Other
138 stars 58 forks source link

get url from ngrok as variable #19

Open cornhundred opened 3 years ago

cornhundred commented 3 years ago

Hi, I'm following this example that shows how to run flask-ngrok using Google Colab (from medium)

!pip install flask-ngrok

from flask_ngrok import run_with_ngrok
from flask import Flask
app = Flask(__name__)
run_with_ngrok(app)   #starts ngrok when the app is run
@app.route("/")
def home():
    return "<h1>Running Flask on Google Colab!</h1>"

app.run()

Everything runs fine, but is there a way I can get the public URL that the app is running on as a variable? I need to pass the URL to another cell and I would prefer to not to have to copy/paste it.

DaryeDev commented 2 years ago

Hey! You can see ngrok's address with this:

tunnel_url = requests.get("http://localhost:4040/api/tunnels").text
j = json.loads(tunnel_url)
tunnel_url = j['tunnels'][0]['public_url']