Cloudflare Argo Tunnel from Node child_process
I have an electron app from which I would like to spawn a child process that executes
cloudflared tunnel --url localhost:3000
inside a certain directory. Executing this from cmd inside that directory instantiates the argo tunnel as expected, and the url works while the process is running. This is how I am executing the command from the electron app:
const { spawn } = require('child_process')
let tunnel = spawn('cloudflared', ['tunnel', '--url', 'localhost:4000'], {
stdio: 'inherit', // Will use process .stdout, .stdin, .stderr
cwd: 'c://cloudflare'
})
I can see the normal console output from cloudflare indicating that the tunnel has been established and my server is responding at some-random-name.trycloudflare.com. However, when the process is started from within the electron app, I get Error 1016 displayed on a cloudflare error page.
Does anyone have experience with Argo Tunnel and child_process?
I was able to get your setup to work on my Mac without issue, so you need to look further into the details of your setup. Here is what I did:
cloudflared
version 2019.8.4 via homebrew
with
brew install cloudflare/cloudflare/cloudflared
cloudflared tunnel --url localhost:3000
cloudflared
had some complaints:
Cannot determine default configuration path. No file [config.yml config.yaml] in [~/.cloudflared ~/.cloudflare-warp ~/cloudflare-warp /usr/local/etc/cloudflared /etc/cloudflared]
cloudflared will not automatically update when run from the shell
unable to connect to the origin error="Get http://localhost:3000: dial tcp [::1]:3000: connect: connection refused"
python -m SimpleHTTPServer 3000
cloudflared tunnel --url localhost:3000
Same complaints, except this time it was able to connect:
Proxying tunnel requests to http://localhost:3000
Further output from cloudflared
indicated it was bringing up 4 tunnels. For each tunnel, it output
+-----------------------------------------------------------+
| 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
Note that I did not change or obfuscate the URL, that is exactly what was output, and cloudflared
output the same URL 4 times, once for each tunnel.
I went to https://sides-universe-gym-metadata.trycloudflare.com and verified it displayed the same website I had brought up on localhost:3000.
I quit cloudflared
by typing ctrl-c
in the Terminal window where it was running. It took quite some time to shut down, but I waited until it quit.
I went to https://sides-universe-gym-metadata.trycloudflare.com and verified it displayed an error. It displayed "Error 1016" and "Origin DNS error".
In Electron Fiddle, I selected Electron v6.0.6
and used the default, pre-installed main.js
, index.html
, and renderer.js
. In main.js
, I added at the bottom
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'
})
cloudflared
.
cloudflared
brought up 4 tunnels, each with the URL https://citysearch-celebs-generator-history.trycloudflare.com
cloudflared
then logged:cloudflared has been updated to version 2019.8.4
PID of the new process is 81076
Quitting...
Metrics server stopped
--is-autoupdated=true
. cloudflared
started logging its startup messages, just as before.cloudflared
kept running. I could still load https://gifts-jpg-treasury-correct.trycloudflare.com/
cloudflared
brought up 4 tunnels. This time it did not auto-update or restart. The 4 new tunnels all had the same new URL: https://reject-pride-built-twisted.trycloudflare.com/
So I cannot reproduce your problem. Possible issues are that you may have been looking at the first tunnel that came up but cloudflared
had updated, closed that tunnel, and started a different one. This worked for me on Mac but it seems you are working on Windows so it could be some Windows-specific issue. It could be that you do not have a server running on localhost:4000
or that your Electron app cannot access C://clouflare
.
You need to provide more information, such as the log output of your Electron app running cloudflared
and details about the server running at localhost:4000
and any cloudflared
configuration files you have set up.
Common cause
Cloudflare cannot resolve the origin web server’s IP address.
Common causes for Error 1016 are:
A missing DNS A record that mentions the origin IP address.
A CNAME record in Cloudflare DNS points to an unresolvable external domain.
The origin host names (CNAMEs) in your Cloudflare Load Balancer default, region, and fallback pools are unresolvable. Use a fallback pool configured with an origin IP as a backup in case all other pools are unavailable.
Resolution
To resolve error 1016:
1) Verify your Cloudflare DNS settings include an A record that points to a valid IP address that resolves via a DNS lookup tool.
2) For a CNAME record pointing to a different domain, ensure that the target domain resolves via a DNS lookup tool.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With