ngrok - 如何找到已用于 ngrok 的子域列表?

标签 ngrok

我们在 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,它不知道互联网上其他地方正在使用的子域。我正在寻找的东西似乎是可能的,因为 ngrok.io 网站本身确实列出了目前正在使用的子域,我只需要弄清楚他们是如何做到的?我使用的是 2.0 版。

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

(一些数字改变了)

t=2015-12-21T16:03:17+0000 lvl=warn msg="无法打开私有(private)分支"id=094b633d8754 privaddr=localhost:4567 err="dial tcp 127.0.0.1:4567:连接被拒绝”

最佳答案

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

List all online tunnels currently running on the account.

关于ngrok - 如何找到已用于 ngrok 的子域列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34439739/

相关文章:

ngrok - 如何使用 Ngrok 为网站添加密码

laravel - 没有任何时间限制的 ngrok 替代方案

ubuntu - 注册 Twilio 电话号码时出现 ngrok 错误

meteor - 如何使用 ngrok 测试接收 Stripe webhook

node.js - 为什么在通过 ngrok 建立隧道时会出现 CORS 错误?

reactjs - 如何*同时*将 ngrok 用于后端和前端?

portforwarding - 如何使用 ngrok 建立隧道端口,将流量转发到本地托管的虚拟机?

ssl - 找不到 ngrok websocket 安全的证书

macos - 在 OSX 上自动启动 ngrok