从节点child_process执行Argo隧道时出现错误1016

Nat*_*ies 8 javascript localhost node.js cloudflare electron

来自节点child_process的Cloudflare Argo隧道

我有一个电子应用程序,希望从中生成一个子进程来执行

cloudflared tunnel --url localhost:3000
Run Code Online (Sandbox Code Playgroud)

在某个目录中。从该目录内的cmd执行此操作将按预期实例化argo隧道,并且该URL在进程运行时起作用。这就是我从电子应用程序执行命令的方式:

const { spawn } = require('child_process')

let tunnel = spawn('cloudflared', ['tunnel', '--url', 'localhost:4000'], {
  stdio: 'inherit', // Will use process .stdout, .stdin, .stderr
  cwd: 'c://cloudflare'
})
Run Code Online (Sandbox Code Playgroud)

我可以看到cloudflare的正常控制台输出,指示隧道已建立,并且我的服务器在some-random-name.trycloudflare.com上响应。但是,当从电子应用程序内部启动该过程时,我在cloudflare错误页面上显示了错误1016。

有人对Argo Tunnel和child_process有经验吗?

Old*_*Pro 3

我能够让您的设置在我的 Mac 上顺利运行,因此您需要进一步了解设置的详细信息。这是我所做的:

  1. 从 GitHub安装Electron Fiddle v0.9.0
  2. 通过with 安装了cloudflared版本 2019.8.4homebrew
    brew install cloudflare/cloudflare/cloudflared
    
    Run Code Online (Sandbox Code Playgroud)
  3. 从命令行(终端窗口)运行
    cloudflared tunnel --url localhost:3000
    
    Run Code Online (Sandbox Code Playgroud) cloudflared有一些抱怨:
    • 无法确定默认配置路径。[~/.cloudflared ~/.cloudflare-warp ~/cloudflare-warp /usr/local/etc/cloudflared /etc/cloudflared] 中没有文件 [config.yml config.yaml]

    • 从 shell 运行时,cloudflared 不会自动更新

    • 无法连接到源错误=“获取http://localhost:3000:拨打tcp [::1]:3000:连接:连接被拒绝”

  4. 在 localhost:3000 上启动了一个 Web 服务器
    python -m SimpleHTTPServer 3000
    
    Run Code Online (Sandbox Code Playgroud)
  5. 在我的浏览器中加载页面http://localhost:3000
  6. 又跑了
    cloudflared tunnel --url localhost:3000
    
    Run Code Online (Sandbox Code Playgroud) 同样的抱怨,除了这次能够连接:

    将隧道请求代理到http://localhost:3000

  7. 进一步的输出cloudflared表明它正在修建 4 条隧道。对于每个隧道,它输出

    +-----------------------------------------------------------+
    |  Your free tunnel has started! Visit it:                  |
    |    https://sides-universe-gym-metadata.trycloudflare.com  |
    +-----------------------------------------------------------+
    Route propagating, it may take up to 1 minute for your new route to become functional
    
    Run Code Online (Sandbox Code Playgroud)

    请注意,我没有更改或混淆 URL,这正是输出的内容,并且cloudflared将相同的 URL 输出 4 次,每个隧道一次。

  8. 我访问https://sides-universe-gym-metadata.trycloudflare.com并验证它显示的网站与我在 localhost:3000 上打开的网站相同。

  9. 我通过在运行它的终端窗口中cloudflared键入内容来 退出。ctrl-c花了相当长的时间才关闭,但我一直等到它退出。

  10. 我访问https://sides-universe-gym-metadata.trycloudflare.com并验证它显示错误。它显示“错误 1016”和“源 DNS 错误”。

  11. 在 Electron Fiddle 中,我选择Electron v6.0.6并使用了默认的、预安装的main.jsindex.htmlrenderer.js。在 中main.js,我在底部添加了

    const { spawn } = require('child_process')
    
    let tunnel = spawn('cloudflared', ['tunnel', '--url', 'localhost:3000'], {
      stdio: 'inherit', // Will use process .stdout, .stdin, .stderr
      cwd: '/Users/user/development'
    })
    
    
    Run Code Online (Sandbox Code Playgroud)
  12. 我点击 Electron Fiddle 上的“运行”。“你好世界!” 页面出现了。Electron 控制台显示了 的输出cloudflared
    • 再次cloudflared出现 4 个隧道,每个隧道的 URL 为https://citysearch-celebs-generator-history.trycloudflare.com
    • cloudflared然后记录:
    • cloudflared 已更新至版本 2019.8.4

    • 新进程的PID为81076

    • 放弃...

    • 指标服务器已停止

    • 我不知道为什么它从“2019.8.4”“更新”到“2019.8.4”。也许它与没有默认配置有关,也许与 Electron Fiddle 从非标准位置运行它有关。我怀疑这是因为命令行不包含--is-autoupdated=true.
    • 在“Metrics 服务器停止”之后立即cloudflared开始记录其启动消息,就像以前一样。
    • 它再次显示 4 个隧道,这次的 URL 为https://gifts-jpg-treasury- Correct.trycloudflare.com
    • 从启动到重新启动到最后稳定隧道运行所用的总时间:14 秒。
  13. 我在本地浏览器中访问https://gifts-jpg-treasury- Correct.trycloudflare.com 并再次获得了我在 localhost:3000 托管的网站。
  14. 我在 Electron 中点击了“停止”。Electron 服务器停止了,但cloudflared仍在运行。我仍然可以加载https://gifts-jpg-treasury- Correct.trycloudflare.com/
  15. 我在 Electron 中点击了“运行”。再次cloudflared提出 4 条隧道。这次它没有自动更新或重新启动。4 个新隧道都有相同的新 URL:https ://reject-pride-built-twisted.trycloudflare.com/
  16. 我在本地浏览器中访问https://reject-pride-built-twisted.trycloudflare.com/并再次获得了我在 localhost:3000 托管的网站。我尝试了https://gifts-jpg-treasury- Correct.trycloudflare.com,它也仍然有效。

所以我无法重现你的问题。可能的问题是,您可能一直在查看出现的第一个隧道,但cloudflared已更新、关闭该隧道并启动了另一个隧道。这在 Mac 上对我有用,但似乎你在 Windows 上工作,所以这可能是一些 Windows 特定的问题。可能是您没有运行服务器localhost:4000或者您的 Electron 应用程序无法访问C://clouflare

您需要提供更多信息,例如运行的 Electron 应用程序的日志输出cloudflared以及有关运行的服务器以及您设置的localhost:4000任何配置文件的详细信息。cloudflared