How can one configure flask to be accessible via public IP interface?

Dark Star1 picture Dark Star1 · Jun 6, 2016 · Viewed 10.8k times · Source

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.

Answer

glls picture glls · Jun 6, 2016

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