What Are We Fighting For?
In a developer’s life, there is regularly a need to show work results to someone else: a colleague, a client, or a tester. Everything is fairly simple if you are sitting in the same room or at least the same building: you can invite them to your desk, most likely promising coffee or cookies, and show everything personally on your own monitor. It is harder if you are in different districts, cities, or even countries. And sometimes you may need an internet-accessible API deployed locally, for example if you are developing or testing mobile applications.
There are many ways to solve the problem. One is to buy a white external IP address, forward ports, buy a domain name, and configure it. It is a complete solution, but not always available: not every provider can give you a white address, and not everyone is ready to let you use the ports you need. Not to mention that you become tied to the chosen provider and cannot use this solution while sitting in a cafe with a work laptop on a broadband connection. You can also rent a server from some host and deploy everything you need to show there first. Here, of course, other problems appear: the server’s performance limits, an extra infrastructure element that needs maintenance, and constant deployment of changes that you only want to show and may not even be ready to commit.
Ngrok Rushes To The Rescue
Ngrok is a service that lets you forward a port from a local computer to ngrok servers. Anyone can access your local application through a globally available service subdomain on .ngrok.io.
Installation
wget https://dl.ngrok.com/ngrok_2.0.19_linux_amd64.zip
unzip ngrok_2.0.19_linux_amd64.zip
mv ngrok /usr/local/bin
sudo chmod +x /usr/local/bin/ngrok
Usage
In the simplest version, this is enough:
ngrok http 80
You will see your tunnel monitor:
Tunnel Status online
Version 2.0.19/2.0.19
Web Interface http://127.0.0.1:4040
Forwarding http://8d323578.ngrok.io -> localhost:80
Forwarding https://8d323578.ngrok.io -> localhost:80
Open our unique address in the browser. Information about our request will appear in the monitor:
HTTP Requests
-------------
GET /favicon.ico 200 OK
GET /css/all.css 200 OK
GET /js/index.js 200 OK
GET /images/loader.gif 200 OK
GET / 200 OK
A nice feature is the ability to enable basic auth by specifying one extra flag:
ngrok http -auth="login:password" 80
You can learn about other service features like this:
ngrok help