【问题标题】:Programmatic ngrok tunnel url程序化 ngrok 隧道 url
【发布时间】:2019-03-27 00:51:16
【问题描述】:

我正在尝试通过使用 bash 设置全局变量和环境变量以编程方式获取 ngrok 动态生成的 IP 地址。

以下是我目前所拥有的。


运行ngrok http {server url}

在您的主机根目录中运行:

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

安装 jq

Brew install [jq](https://stedolan.github.io/jq/)(让你通过bash访问json)

之后你只需要按照 jq 的文档访问这个 json。

在调用开发 URL 的项目根目录中。 [0]=(http) [1]=(https)

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

将您的所有开发网址设置为 process.env.NGROK_TUNNEL


所以这行得通,但它是“最佳方式”吗?

【问题讨论】:

    标签: bash shortcut ngrok


    【解决方案1】:

    对于想要使用 python 通过 ngrok 获取 url 的人,the pyngrok library

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

    也可以通过 ngrok API 直接做一些事情。我没有找到创建隧道的选项,但是创建隧道后,您可以重新启动或更新它

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

    【讨论】:

      【解决方案2】:

      简短的回答是肯定的。

      您可以升级到paid plan 并使用--subdomain 参数每次都获得相同的ngrok url。下一个价格水平包括白标,您也可以在其中使用自己的自定义域。

      【讨论】:

        猜你喜欢
        • 2019-12-04
        • 2016-09-18
        • 2017-02-21
        • 2015-03-11
        • 2021-04-16
        • 2019-07-14
        • 2016-02-26
        • 2020-05-09
        • 2020-10-05
        相关资源
        最近更新 更多