Overview
Thetunnel command creates a secure Cloudflare tunnel that exposes a local port to the internet. It automatically generates a public URL and displays a QR code for easy sharing.
Syntax
Parameters
The local port number to tunnel. This is the port where your local service is running.Aliases:
-pUsage Examples
Output
When successful, the command displays:- A spinner message: “Starting tunnel, this may take a second…”
- The tunnel URL (e.g.,
https://xyz-abc.trycloudflare.com) - A QR code containing the tunnel URL for easy mobile access
Example Output
Return Value
The underlyingtunnel() function returns an object with:
url: The public tunnel URL (string)kill: Function to terminate the tunnel process
{}.
Error Handling
The command handles the following errors:Rate Limit Error
If you see “429 Too Many Requests”, the command will display:Connection Failures
The tunnel monitors the Cloudflare process output for:- Invalid character errors
- Connection registration success
- Rate limit responses
Technical Details
Implementation
The tunnel command uses Cloudflare’scloudflared binary to create a quick tunnel. The implementation:
- Spawns a
cloudflared tunnel --url http://localhost:<port>process - Monitors the stderr output for the tunnel URL
- Extracts the URL using regex:
/https:\/\/[a-zA-Z0-9-]+\.trycloudflare\.com/ - Waits for “Registered tunnel connection” confirmation
- Returns the URL and process control
URL Pattern
Cloudflare generates URLs matching the pattern:Notes
The tunnel process runs in the background and continues until you terminate the CLI. The tunnel will close when you exit the process.
Ensure
cloudflared is installed on your system. The Ahh CLI requires this dependency to create tunnels.