官术网_书友最值得收藏!

Exposing your Azure Functions on the internet with ngrok

As you have read in the previous paragraphs, you can use the Azure Functions runtime to host your functions, but the host process exposes your function on the localhost, so you cannot reach them from another PC than the one hosting them.

If you want to expose your functions on the internet and, therefore, solve the problem, you can use ngrok. ngrok is software (running on Windows, macOS, and Linux) that allows you to expose a local server to the internet using a secure tunnel, and it also works if your local server is behind a NAT or a firewall.

  1. To use ngrok, you need to register yourself on the ngrok website and create an account.

ngrok has a free plan that allows you to use the software for free with the limitation of only one process at a time with a maximum of four tunnels and a random port, but it is enough to test your functions.

You can create your own account at https://ngrok.com and download the ngrok client from https://ngrok.com/download. You also find the complete documentation at https://ngrok.com/docs.
  1. Once you download the ngrok client, you have to connect your account to the client (you need to do this operation once only) using the following command:
ngrok.exe authtoken <your_auth_token>

You can find your authentication token in the Auth section of your account dashboard:

  1. To expose your local function using ngrok, simply expose the local port using the http command:
C:>func host start --port 9999
C:>grok http 9999

The following screenshot shows the output of the preceding command:

The http command starts a tunnel from a random subdomain hosted by the ngrok platform (in the previous screenshot, a84984cb.eu.ngrok.io) to your PC. You can call your Azure Functions using the sub-domain instead, http://localhost; for example, if your function has the http://localhost:9999/api/books URL, you call it using the http://a84984cb.eu.ngrok.io/api/book URL.

The ngrok console shows the HTTP requests received through the tunnel, but ngrok also exposes a web GUI you can display using the http://localhost:4040 URL. The web console shows you all the requests received by the ngrok tunnel, as you can see in the following screenshot:

This is a screenshot of the web console which shows you all the requests received by the ngrok tunnel. The text and numbers in this image are intentionally illegible

And it also shows you the metrics about your connection, as you can see in the following screenshot:

This is a screenshot of the web console which shows you the metrics about your connection. The text and numbers in this image are intentionally illegible

The web GUI allows you to inspect every single request received and gives you information about the tunnel and statistics about the requests (for example, connections and request duration).

主站蜘蛛池模板: 武汉市| 金沙县| 静安区| 贵德县| 郯城县| 东方市| 广水市| 定边县| 清水县| 砚山县| 宜丰县| 望江县| 新绛县| 察隅县| 衡山县| 海兴县| 永胜县| 桂阳县| 大同县| 嘉鱼县| 枣庄市| 伊金霍洛旗| 太和县| 房产| 册亨县| 唐海县| 焦作市| 岳池县| 松潘县| 德清县| 绵阳市| 明星| 铜陵市| 涡阳县| 威海市| 彭州市| 施甸县| 舟曲县| 静海县| 博湖县| 铁岭县|