【问题标题】:How do I find a list of subdomains already in use with ngrok?如何找到已与 ngrok 一起使用的子域列表?
【发布时间】:2016-03-30 03:04:37
【问题描述】:

我们在 CI 构建中使用 ngrok,以便使用第三方服务测试 API。事实证明,这非常成功,只是支持并发构建似乎要困难得多。

为了支持并发,我们决定获取保留域,比如说:

  • 自定义域
  • 自定义域2
  • 自定义域3

我编写了一个脚本来检查可用域,并使用它找到的第一个可用域。该脚本很粗糙,当我们尝试使用已在使用的子域时,它依赖于 ngrok 终止:

#!/bin/bash

wget https://dl.ngrok.com/ngrok_2.0.19_linux_amd64.zip
unzip ngrok_2.0.19_linux_amd64.zip
./ngrok authtoken <account_token>
./ngrok http -subdomain=custom-domain 5000 &
sleep 5
curl http://localhost:4040/status
if [[ $? -eq 0 ]]
then
  export HOST=custom-domain.ngrok.io
else
  ./ngrok http -subdomain=custom-domain2 5000 &
  sleep 5
  curl http://localhost:4040/status
  if [[ $? -eq 0 ]]
  then
    export HOST=custom-domain2.ngrok.io
  else
    ./ngrok http -subdomain=custom-domain3 5000 &
    sleep 5
    curl http://localhost:4040/status
    if [[ $? -eq 0 ]]
    then
      export HOST=custom-domain3.ngrok.io
    else
      exit 1
    fi
  fi
fi

我尝试重构它以使用客户端 API,但客户端 API 仅查看 localhost,它不知道 Internet 上其他地方使用的子域。我正在寻找的似乎是可能的,因为 ngrok.io 网站本身确实列出了目前正在使用的子域,我只需要弄清楚他们是如何做到的?我使用的是 2.0 版。

使用脚本方法,它在使用custom-domain 时似乎确实有效,但是在使用2 或3 时,当POST 到达端点时,我们似乎得到了错误,日志中唯一可疑的是:

(一些数字改变了)

t=2015-12-21T16:03:17+0000 lvl=warn msg="failed to open private leg" id=094b633d8754 privaddr=localhost:4567 err="dial tcp 127.0.0.1:4567: connection refused"

【问题讨论】:

    标签: ngrok


    【解决方案1】:

    ngrok 的 REST API 有一个 endpoint for listing all online tunnels

    列出当前在帐户上运行的所有在线隧道。

    【讨论】:

    • 鼓励链接到外部资源,但请在链接周围添加上下文,以便您的其他用户了解它是什么以及为什么存在。始终引用重要链接中最相关的部分,以防目标站点无法访问或永久离线。
    最近更新 更多