简体   繁体   English

程序化的 ngrok 隧道 URL

[英]Programmatic ngrok tunnel url

I'm trying to get ngrok's dynamically generated IP address programmatically by using bash to set globals and env variables.我试图通过使用 bash 设置全局变量和环境变量以编程方式获取 ngrok 的动态生成的 IP 地址。

Below is what I have so far.以下是我到目前为止所拥有的。


Run ngrok http {server url}运行ngrok http {server url}

Inside your host root directory run:在您的主机根目录中运行:

curl  http://localhost:4040/api/tunnels > ~/ngrok_tunnels.json;

Install jq安装 jq

Brew install [jq](https://stedolan.github.io/jq/) (let's you access json through bash) Brew install [jq](https://stedolan.github.io/jq/) (让你通过bash访问json)

Afterwards you just need to access this json following jq's docs.之后,您只需要按照 jq 的文档访问此 json。

Inside the project root that is calling the dev URL.在调用开发 URL 的项目根目录中。 [0]=(http) [1]=(https) [0]=(http) [1]=(https)

echo “NGROK_TUNNEL=$(jq .tunnels[1].public_url ~/ngrok_tunnels.json
)" >> .env

Set all of your dev urls to process.env.NGROK_TUNNEL将所有开发网址设置为process.env.NGROK_TUNNEL


So this works, but is it the "best way" to do this?所以这是有效的,但这是做到这一点的“最佳方式”吗?

For people who want to get a url through ngrok using python there is the pyngrok library对于想要使用 python 通过 ngrok 获取 url 的人,有pyngrok 库

from pyngrok import ngrok

#Open a HTTP tunnel on the default port 80
#<NgrokTunnel: "http://<public_sub>.ngrok.io" -> "http://localhost:80">
http_tunnel = ngrok.connect()
#Open a SSH tunnel
#<NgrokTunnel: "tcp://0.tcp.ngrok.io:12345" -> "localhost:22">
ssh_tunnel = ngrok.connect(22, "tcp")

it is also possible to do some things directly via the ngrok API.也可以直接通过 ngrok API 做一些事情。 I didn't find the option to create a tunnel, but having a tunnel created you can restart it or update it我没有找到创建隧道的选项,但是创建了隧道后,您可以重新启动它或更新它

https://ngrok.com/docs/api#api-tunnel-sessions-list https://ngrok.com/docs/api#api-tunnel-sessions-list

The short answer is yes. 简短的答案是肯定的。

You can upgrade to a paid plan and use the --subdomain argument to get the same ngrok url every time. 您可以升级到付费计划,并使用--subdomain参数每次获取相同的ngrok网址。 The next price level from that includes white labeling where you can use your own custom domain as well. 接下来的价格水平包括白色标签,您也可以在其中使用自己的自定义域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM