alexdlaird / pyngrok

A Python wrapper for ngrok
https://pyngrok.readthedocs.io
MIT License
416 stars 59 forks source link

how to run flask from static url provided by ngrok for free? i always get CORS error when a random url is generated/ #128

Closed Tejnium closed 5 months ago

Tejnium commented 5 months ago

Acknowledgements

Describe the Feature

how to run flask from static url provided by ngrok for free? i always get CORS error when a random url is generated/

i am still not able to run it

!pip install Flask

!pip install pyngrok

!ngrok config add-authtoken xxxxxxxxxxxxxxxxxxxxxxxxx from flask import Flask, request from pyngrok import ngrok

app = Flask(name)

@app.route('/', methods=['GET', 'POST']) def home(): if request.method == 'POST': return 'POST request received!' else: return 'GET request received!'

if name == 'main':

Update the ngrok connect line with your custom domain

public_url = ngrok.connect(addr="80", options={"subdomain": "xxxxx-xxxx-dove"})
print(f'Running server at {public_url}')
app.run(port=80) 

This is just for an example tp make sure instead of localhostL5000 the subdomain is started from the static url

Describe Alternative Solutions/Workarounds

i am suggesting if there is a way to get a free static url from ngrok which can help run the flask apploication and then use that same again and again .

alexdlaird commented 5 months ago

There are a number of ways to do this, at least one is described in the docs using Cloud Edge.

Tejnium commented 5 months ago

from flask import Flask, request from pyngrok import ngrok, conf from pyngrok.conf import PyngrokConfig

Set the API key

conf.get_default().api_key = ""

conf.get_default().config_path = "config.yml" app = Flask(name) conf.get_default().region = "au"

@app.route('/', methods=['GET', 'POST']) def home(): if request.method == 'POST': return 'POST request received!' else: return 'GET request received!'

if name == 'main':

Update the ngrok connect line with your custom domain

public_url =  ngrok.connect(name = "some-edge-tunnel")
print(f'Running server at {public_url}')
app.run(port=80)

i have run this

and this is my config.yml file

tunnels: some-edge-tunnel: labels:

what am i ding wrong?

alexdlaird commented 5 months ago

Some tips for asking good questions: