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

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).

主站蜘蛛池模板: 团风县| 英德市| 阳高县| 金湖县| 林西县| 剑河县| 阳信县| 清水河县| 黔西| 漯河市| 哈密市| 福建省| 郧西县| 鄢陵县| 金寨县| 高平市| 忻州市| 金山区| 莲花县| 太仓市| 江都市| 沾化县| 馆陶县| 同江市| 昌图县| 锡林浩特市| 东兰县| 夏津县| 西乌珠穆沁旗| 新泰市| 吴堡县| 会东县| 抚州市| 双辽市| 莎车县| 邛崃市| 永吉县| 乃东县| 孟州市| 凤城市| 哈巴河县|