Deploy and Access Flask App on Windows Server [No CGI]
![Deploy and Access Flask App on Windows Server [No CGI]](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1639120854833%2Ft8KDePUF_.png&w=3840&q=75)
Quite often you might find a need to deploy your flask application on a Windows Server manually. Though this might not really be a thing in the modern development space due to new technologies (e.g docker) that are revolutionising application development and deployment; mine was prompted by a peer need. We were working around having a consistent development version and don't want to spend extra bucks/resources setting up a CI/CD and the likes so we opted to put it on an existing VPS.
I was saddled with the responsibility of setting this up, and that won't be much of a problem (at least I thought). Everything was going pretty well until I can't access the deployed application externally. All walkthrough I could find online require me to use FastCGI, but I was quite unlucky installing it.

Then I found another way around...
Open port for TCP access
To allow HTTP traffic to your application's port, we need to open a static port in the Windows firewall for TCP access. There are many ways this could be done (e.g CMD, control panel etc) but I used the CMD. Simply run to open port 8001
netsh advfirewall firewall add rule name="TCP Port 8001" dir=in action=allow protocol=TCP localport=8001
In case you need to close the port, run the command below
netsh advfirewall firewall delete rule name="TCP Port 8001" protocol=TCP localport=8001
Set Flask server host to 0.0.0.0
The default host used by Flask server is 127.0.0.1, this make the server accessible only by the network serving Flask, i.e your local computer.
The last piece is to make the server publicly available; set the Flask host to 0.0.0.0.
To change the port, simply run your Flask project using
flask run --host=0.0.0.0
Access the application over the internet
Your application is now published and can be accessed outside your server.
Use your machine IP/domain name and port. e.g http://192.168.28.20:8001
Thanks for your time!

