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有经验吗?
我能够让您的设置在我的 Mac 上顺利运行,因此您需要进一步了解设置的详细信息。这是我所做的:
cloudflared
版本 2019.8.4homebrew
brew install cloudflare/cloudflare/cloudflared
Run Code Online (Sandbox Code Playgroud)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:连接:连接被拒绝”
python -m SimpleHTTPServer 3000
Run Code Online (Sandbox Code Playgroud)cloudflared tunnel --url localhost:3000
Run Code Online (Sandbox Code Playgroud)
同样的抱怨,除了这次能够连接:
将隧道请求代理到http://localhost:3000
进一步的输出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 次,每个隧道一次。
我访问https://sides-universe-gym-metadata.trycloudflare.com并验证它显示的网站与我在 localhost:3000 上打开的网站相同。
我通过在运行它的终端窗口中cloudflared
键入内容来 退出。ctrl-c
花了相当长的时间才关闭,但我一直等到它退出。
我访问https://sides-universe-gym-metadata.trycloudflare.com并验证它显示错误。它显示“错误 1016”和“源 DNS 错误”。
在 Electron Fiddle 中,我选择Electron v6.0.6
并使用了默认的、预安装的main.js
、index.html
和renderer.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)cloudflared
。
cloudflared
出现 4 个隧道,每个隧道的 URL 为https://citysearch-celebs-generator-history.trycloudflare.comcloudflared
然后记录:cloudflared 已更新至版本 2019.8.4
新进程的PID为81076
放弃...
指标服务器已停止
--is-autoupdated=true
.cloudflared
开始记录其启动消息,就像以前一样。cloudflared
仍在运行。我仍然可以加载https://gifts-jpg-treasury- Correct.trycloudflare.com/cloudflared
提出 4 条隧道。这次它没有自动更新或重新启动。4 个新隧道都有相同的新 URL:https ://reject-pride-built-twisted.trycloudflare.com/所以我无法重现你的问题。可能的问题是,您可能一直在查看出现的第一个隧道,但cloudflared
已更新、关闭该隧道并启动了另一个隧道。这在 Mac 上对我有用,但似乎你在 Windows 上工作,所以这可能是一些 Windows 特定的问题。可能是您没有运行服务器localhost:4000
或者您的 Electron 应用程序无法访问C://clouflare
。
您需要提供更多信息,例如运行的 Electron 应用程序的日志输出cloudflared
以及有关运行的服务器以及您设置的localhost:4000
任何配置文件的详细信息。cloudflared
归档时间: |
|
查看次数: |
149 次 |
最近记录: |