1

I programmed a flask backend, and made it work on my local network (wifi, ethernet etc). However I can't manage to expand it so external searches reach it. The code for the backend looks like this:

import os
from flask import Flask, flash, request, redirect, url_for, send_from_directory
from waitress import serve
other imports...

app = Flask(__name__)
app.secret_key = os.urandom(24)
.....
if __name__ == '__main__':
serve(app,host='0.0.0.0',port=5000)

How should I give the server an external IP?

nyenyu
  • 79
  • 1
  • 9

1 Answers1

2

If I can make a suggestion, did you try using gevent? It provides a WSGI standalone server for you to replace the built-in option shipped with Flask.

It is very straightforward to use it:

pip install gevent

And you can plug into your app like this:

import os
from gevent.pywsgi import WSGIServer # Imports the WSGIServer
from gevent import monkey; monkey.patch_all() 
from flask import Flask, flash, request, redirect, url_for, send_from_directory


app = Flask(__name__)
app.secret_key = os.urandom(24)


if __name__ == '__main__':
    LISTEN = ('0.0.0.0',5000)

    http_server = WSGIServer( LISTEN, app )
    http_server.serve_forever()

Gevent also provides support for SSL

You can use it on its own or along with gunicorn or circusd I hope it helps you!

marcosmcb
  • 21
  • 3
  • I ended up hosting the app on a cloud, however i might try this aproach. – nyenyu Dec 07 '18 at 17:46
  • Just bear in mind that you should have a Public IP address set up on the machine you are running the app from. The code snippet that I posted shows a way of replacing the built-in server that comes with Flask, that is an alternative that works smoothly with Windows. – marcosmcb Dec 10 '18 at 09:24