Expose a local web server to the internet (Example : Flask app)

Expose a local web server to the internet (Example : Flask app)

Before deploying the web-app to production, it's always a good practice to test it on different devices.

Like, Test the responsiveness of your web-app on mobile.

So for this, we need a public-url, So that we can access that web-app from our mobile-phone.

To solve above problem, we have 'ngrok'

ngrok allows you to expose a web server running on your local machine to the internet.

Step1

Download the ngrok and install it on your system.

ngrok.com/download

In Linux Ubuntu run below command to install.

carbon(1).png

Step2

Write your flask app code and run it locally on your machine

carbon(2)(1).png

Screenshot from 2021-01-31 18-51-26.png

So Now, our application is running locally on port 5001.

Do Not, close or terminate this terminal.

Step3

Open the New terminal window for Step3 i.e. exposing the local server to the internet

Just run below command

Just tell ngrok what port your web server is listening on. In our case it's 5001. If you don't know what port your web server is listening on, it's probably port 80, the default for HTTP.

carbon(3)(1).png

When you enter above ngrok command, it will display a UI in your terminal with the public URL of your tunnel and other status and metrics information about connections made over your tunnel.

Screenshot from 2021-01-31 18-51-15.png

All Done !!

Just browse the highlighted URL in your mobile-phone.