ngrok : Testing localhost with remote API

You are developing a web stuff and you want to use any remote-API or any web-service but due to localhost, you can't do it like integration testing with Payment Gateway. In that case, you need a static IP.

Now think if any domain name is allocated to localhost (your development machine) and you don't need to purchase a static IP for this task, then you can easily test, debug and provide fixes immediately.  Even you can share website on web from your localhost machine.

How ?
The simple answer is a ngrok. It will provide you a subdomain for your localhost.

ngrok is an open-source project which provides a reverse-proxy that creates a secure tunnel between web to your local-machine. Its available for Linux, Windows and Mac-OS.

No need to sign up, easy to setup and easy to use

What you can do ?
  • Share your website demo that is running on your development machine.
  • Developing and testing any application which consume webhooks like Notification of payment, test social-media registration locally etc.
  • HTTP/Token based authentication on your tunnel.  (sign-up feature)
  • Reserved sub-domain for your tunnel. (Paid-feature)

Set-up on Ubuntu :
1# Download binary file from ngrok official site.
2# unzip it and get binary file (ngrok)
unzip /loaction/of/ngrok.zip
Now every task of ngrok will be executed by binary file execution ( ./ngrok).
Its far better, If you will move this binary file to /usr/bin/ folder so you can use ngrok as command on terminal at anywhere.
sudo mv /binary/file/loaction/ngrok /usr/bin/
3# Setup is completed and now you can create a tunnel. 
 You need to bind port number on tunnel. Like apache uses port number 80 by-default. So execute the following command

ngrok 80
Tunnel status will be open and you will get a sub-doamin.

ngrok-tunnel


You can see here all http request and you can inspect your all http request(traffic) on http://localhost:4040. Here you can replay all request.
You can get help by ngrok --help  or prefer ngrok doc for more advance information.

I have tested ngrok on PayInvoice extension ( A Joomla based Invoicing system) with Paypal Payment processor.  :)

Comments