Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
2 tasks done
Tejnium opened this issue Jan 26, 2024 · 3 comments
Labels
invalid This doesn't seem right

Comments

@Tejnium
Copy link

Tejnium commented Jan 26, 2024

Acknowledgements

  • I have written a descriptive issue title
  • I have searched Issues to see if the feature has already been requested

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 .

@Tejnium Tejnium added the enhancement New feature or request label Jan 26, 2024
@alexdlaird
Copy link
Owner

alexdlaird commented Jan 26, 2024

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

@alexdlaird alexdlaird added invalid This doesn't seem right and removed enhancement New feature or request labels Jan 26, 2024
@Tejnium
Copy link
Author

Tejnium commented Jan 26, 2024

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

Set the API key

conf.get_default().api_key = "<your_ngrok_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:
- edge=edghts_xxxxxxxxxxxxxxxxxxx
addr: 80

what am i ding wrong?

@alexdlaird
Copy link
Owner

Some tips for asking good questions:

  • When you think you're experiencing an error, provide the accompanying output, otherwise those trying to help you have nothing to go off of.
  • Format code properly, otherwise those trying to help you can't simply copy/paste to reproduce your experience with the code.
  • For the context of this library, provide the comparable ngrok command that shows what you want to do / why it should work in pyngrok, otherwise with so little other information, those trying to help you can't understand where you're trying to get to.
  • Ask questions in the relevant context, which continues to be Stack Overflow unless a bug or missing functionality is actually shown in the description provided (which is not the case here).

Repository owner locked as off-topic and limited conversation to collaborators Jan 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants