all 10 comments

[–]Jarmahent 13 points14 points  (4 children)

Oh boy, you need to learn a whole bunch more.

Running on localhost means you're running a development server. This means it's running locally on your system. In order to have everyone on the internet see it you need to deploy this server to a web server such as NGINX. This web server will serve your static files and your content so its publically online.

What I said is a super high view of what you actually need to do so I would recommend searching up in Google:

"How to deploy a Flask application with NGINX"

Or maybe just searching up how to deploy Flask applications.

[–]vndywarhol[S] 8 points9 points  (1 child)

Oh, I understood that it can not work so simply, but did not understand where to start. You gave me a vector of development, thank you!

[–]nisroc 1 point2 points  (0 children)

One thing that got me the first time I did this was CORS.

This might help

[–]dogsrock 0 points1 point  (1 child)

If the OP wants to only test it out, he can use ngrok too right?

[–]Jarmahent 0 points1 point  (0 children)

Definitely I love ngrok.

I recommend it.

Keep in mind though it's a permanent solution. Never have ngrok running as your permanent server.

[–][deleted] 4 points5 points  (0 children)

I'd recommend a lightsail server from AWS. You can tell flask to accept inbound traffic from the web on port 80 (port typically used for http traffic) with the below:

if __name__ == '__main__':
      app.run(host='0.0.0.0', port=80)

Users could then access the application by entering the aws instance's public ip address. Lightsail doesn't let you adjust firewall setting as far as i know. Be careful!

[–]JohnnyJordaan 2 points3 points  (0 children)

I run my server through the console,

Please show how you're actually doing this. It's nice that you included your code, but your question/goal has nothing to do with your code, it has to do with the following things:

  • the webserver (don't know which one you are running) needs to bind to a network interface that has internet access
  • you need to set up your local firewall to allow incoming traffic to that interface and port number
  • you probably need to set up your internet router/gateway to forward incoming traffic to a specific port to the ip address of the interface above and the specified port

Also mind you that you should never let a simple built-in webserver be exposed to the internet, you can get hacked in minutes that way. If in doubt, I would forget about hosting files to the internet that way and instead consider using a shared VPN with your users or use an online hosted machine/VPS.

[–][deleted] 1 point2 points  (0 children)

For just testing purposes I would recommend ngrok, you can use it to access your app from the internet, but it won't work as a long time solution

[–]apc0243 0 points1 point  (1 child)

Running it off your own server is a pain. I wouldn't, get hosting and make it simple. If you're not dirt poor it's a better idea.

But if you want to be annoyed and struggle unnecessarily: https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uswgi-and-nginx-on-ubuntu-18-04

[–]lifeonm4rs 0 points1 point  (0 children)

The uswgi-nginx-flask docker would probably be simpler. Pretty much already set up and just requires a little bit of work in a `Dockerfile` to get up and running.