Ngrok <3
I’m a fan of Ngrok. ‘What is Ngrok?’ I hear you cry. Ngrok, is an infuriatingly useful tool - allow me to explain.
There are things known as ‘webhooks’, an address for a message to be sent to when an event occurs. When the message is sent to that address the webhook captures the message and processes it in a useful way.
For instance, if you send email using a service like SendGrid there’s an option to have events like emails being opened to a webhook. You can then take the message sent to that webhook and use it to store information about who opened it, when they opened it, and what email client they opened the email in.
If that sounds great to you, then it should. Webhooks are really useful. The issue comes when you are testing your webhook. The quickest way for testing an application you’re writing is to write it on your computer and run it there too. How then, do you give a web address for your computer to the service that will call your webhook?
Enter Ngrok!
Ngrok, a tiny command line application, gives you the ability to temporarily give a specific port on your machine a web address. Now we can test our webhook!
The problem is that if you run Ngrok on Windows you’ll often run into 404 errors. Fixing these in my experience has involved a whole heap of command line commands and editing your web server’s config file - all very unpleasant, prone to error, and time-consuming.
The error is caused because the hostname on the incoming request matches the web address given to you by Ngrok rather than your machine’s local address.
Ngrok to the Rescue (Again)
I recently learnt Ngrok has a command to fix this!
ngrok.exe http -host-header=rewrite localhost:YOURLOCALPORT
This command has saved me so much time over the past few weeks and turns webhook debugging into something I no longer fear. Enjoy!