1

I have made an flask API which would take input directory as input parameter by get http request. It is working fine on port 5000 on the local machine. Now I want that working api to run on a web server so that I can use it over internet. I tried apache 2 server to do the work but it wasn't successful.

    # API
app = Flask(__name__)

@app.route('/')
def home():
    return  "HOME PAGE LOADED"

@app.route('/runDocumentManager', methods=["GET"])
def runDocumentManager():
    # pdf path
    file = request.args.get('input_path')

.
.
.
if __name__ == '__main__':
    app.run()
Mousam Singh
  • 675
  • 2
  • 9
  • 29
  • check this [digital ocean](https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uswgi-and-nginx-on-ubuntu-18-04) – Ja8zyjits Mar 19 '19 at 11:15

1 Answers1

3

Once you start your website it will be hosted on localhost:5000
So you want to make it host on your network first. Do so with:

 app.run(host="0.0.0.0")

This will make your app run on your local network.
Then you will need to portforward it on your router. This is so that if someone types in your ip then it will send them to your router.
There you want your router to route it to your machine's server.
So if someone connects to (Your IP):5000 then it will place them on (192.168.0.X):5000 (aka. The server python webserver you are running). I highly recomend googling on how to portforward as it differs slightly on different routers

Usualy you can find it at either:

  1. https://192.168.0.1
  2. https://192.168.1.1
  3. https://192.168.2.1

You might be required to type in the password and username which usualy is "admin" for both but may be different depending on your ISP. You can check that online as well.

Artur Wagner
  • 56
  • 1
  • 6
  • I did the same but on opening server's homepage it is showing default page of apache 2 – Mousam Singh Mar 19 '19 at 12:03
  • 1
    You don't need apache (Don't run it). Just run your python script because apache will run its own files from htdocs in xampp (if you use xampp). Just run your python script and done!. You will just need to portforward any outside connections to your ip to your computer. In the end you will do MYIP:5000 to connect to your website. – Artur Wagner Mar 19 '19 at 13:11
  • Yes I got it. I knew it runs on IP:5000 but on the local machine but I wanted the api to be across the whole network, and putting host as 0.0.0.0 worked for me. – Mousam Singh Mar 20 '19 at 06:46