Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 708
Dark Star1 Avatar asked Jun 06 '16 15:06

Dark Star1


1 Answers

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

like image 123
glls Avatar answered Nov 14 '22 21:11

glls