How can one configure flask to be accessible via public IP interface?
run flask using
app.run(host="0.0.0.0:PORT#")
look for your IPv4 Address using ifconfig
in your command prompt, and in your browser you can access your app using your ipaddress:port#
You might have to configure your router (port forwarding) to make it publicly available, otherwise you can download/use https://ngrok.com/ ----> This will expose your localhost behind a NaT or Firewall to the internet.
Once you download, you can configure it by running
ngrok http localhost:5000
this will provide you a RANDOMsubdomain.ngrok.io and you can test your app from pretty much anywhere
Dark Star1
The true mind can weather all the lies and illusions without being lost. The true heart can toughen the poison of hatred without being harmed. Since beginning-less time, darkness thrives in the void, but always yields to purifying light.
Updated on June 18, 2022Comments
-
Dark Star1 almost 2 years
I am unable to resolve any methods externally via their url once I set the SERVER_NAME or host property in flask. The following is my app init config:
flask_sqlalchemy import SQLAlchemy from flask.ext.cors import CORS __authors__ = 'DarkStar1' from flask import Flask app = Flask(__name__) app.config.from_object('config') app.config['DEBUG'] = True app.config['SERVER_NAME'] = '0.0.0.0' #app.run(host='0.0.0.0') CORS(app) db = SQLAlchemy(app) from oms import user_service, person_service
I can set the DEBUG param/property but attempting to set the host or SERVER_NAME results in all urls, http://< hostname >:5000/test for example, resulting in 404s. Since the server is a remote dev server, I am able to tunnel and get 200s on all urls from flask via localhost. The port is enabled and the flask version I am working with is 0.10.1 on python 2.7.6. I have search and read docs to no avail.
-
Dark Star1 almost 8 yearsrun.app() or app.run()?
-
Dark Star1 almost 8 yearsGot it up and running with app.run(host="0.0.0.0")
-
glls almost 8 yearsI had forgotten to add host and the quotes, thx
-
alexdlaird about 4 yearsEven simpler, use
pyngrok
(pip install pyngrok
) to invoke and managengrok
right from within yourserver.py
. Here's a full Flask example, but basically you'd just need tofrom pyngrok import ngrok
and thenngrok.connect(5000)
when you're defining the routes. -
glls about 4 yearsnice, did not know of this.