cloudflared icon indicating copy to clipboard operation
cloudflared copied to clipboard

💡 A mechanism to retrieve the currently running quick tunnels

Open davidbarratt opened this issue 1 year ago • 4 comments

Describe the feature you'd like When you startup a quick tunnel, it's difficult to access the current URL for that tunnel. This makes it difficult to create dev scripts using tunnels.

Describe alternatives you've considered Shopify's CLI uses tunnels as part of their development workflow, but the only way it looks like they could accomplish this was from parsing the log stream: https://github.com/Shopify/cli/blob/f74d9909f4c7ffbc9d7b7a1af17d7cd5f3d8cf8c/packages/plugin-cloudflare/src/tunnel.ts#L207-L210

Additional context As part of multiple applications, I wanted to have a script that would startup a development environment (i.e. npm dev) and have that script startup a Cloudflare Quick Tunnel and open the URL in the default web browser. It can be difficult to determine the correct URL to open.

davidbarratt avatar May 29 '24 17:05 davidbarratt

@davidbarratt You can query the cloudflared metrics port for the QuickTunnel URL. We will update our developer docs with this info. http://localhost:<METRICS_PORT>/quicktunnelurl

janani-cr avatar Jun 03 '24 15:06 janani-cr

@janani-cr I would really like to be able to retrieve the URL too, but I am a bit unsure how to retrieve it. When I start my tunnel:

cloudflared tunnel --url localhost:8080

It starts my metrics server on: 127.0.0.1:60246/metrics.

Trying to access your URL returns 404: 127.0.0.1:60246/quicktunnelurl

The same happens when using the --hello-world tunnel.

What am I doing wrong?

(Cloudflared version: cloudflared version 2024.7.1 (built 2024-07-16T15:24:52Z))

JanmanX avatar Jul 24 '24 14:07 JanmanX

For anyone in the future, the endpoint to get the URL is http://127.0.0.1:<metrics_port>/quicktunnel. If this ever stops working, check this line https://github.com/cloudflare/cloudflared/blob/2feccd772c7bfe37e43531cf7524deb30190de8b/metrics/metrics.go#L81

Response from this endpoint is a JSON object with a key of hostname and the value being the URL

ColeDenslow avatar Jan 31 '25 10:01 ColeDenslow

Thank y'all so much for this! This is perfect ❤️

ericclemmons avatar Apr 13 '25 21:04 ericclemmons