Azure Functions are a great example of how serverless is conquering the cloud world we live in today. There are also many blogs in how-to-write-functions out there, of which the latest use the precompiled functions, in Visual Studio 2017.
Think of a scenario, where you want to test a LogicApp against your function, but that app obviously cannot connect to localhost. You have two options; You can deploy the Functions app to Azure and use remote debugging or you can use your own localhost, with the use of ngrok.
This blog will explain how to debug locally, when using other services in the cloud.
First of all, we start off with a very simple function:
Running this will result in something like this:
That is it; and your function is running locally. Calling it with Chrome will spit out a simple JSON:
Downloading and installing ngrok is extremely easy from their webpage: https://ngrok.com/download. Using the following line, we will make our localhost on port 7071 (default for Functions) project accessible from the internet:
Please note that I’ve added -host-header due to some issues that could arise when mapping to localhost from the internet.
The ngrok command results in ngrok running:
Testing the tunnel
By calling our function, but now using the ngrok hostname provided, we get the exact same output:
If you have any need of testing output of a webhook of any kind; check out Requestbin! This site will let you create a ‘bin’ for your requests, and will show any POST/GET or other data pointed at it. Could be very usefull when debugging output of LogicApps when you use JSON compose and want to inspect your output!