cftpipe.sh is a command-line tool for managing Cloudflare Tunnels, allowing you to easily expose local web servers to the internet.
Before using this script, ensure you have the following tools installed:
cloudflared: The Cloudflare Tunnel daemon.jq: A lightweight and flexible command-line JSON processor.curl: A tool to transfer data from or to a server.openssl: For generating random IDs.
The script requires the following environment variables to be set:
CF_API_TOKEN: Your Cloudflare API token with permissions to edit DNS and Cloudflare Tunnels.CF_ACCOUNT_ID(optional): Your Cloudflare Account ID. If not set, the script will prompt you for it during setup.
You can export them in your shell configuration file (e.g., ~/.zshrc or ~/.bashrc):
export CF_API_TOKEN="your_cloudflare_api_token"
export CF_ACCOUNT_ID="your_cloudflare_account_id"The script supports the following commands:
Initializes the Cloudflare Tunnel configuration. This command only needs to be run once.
Usage:
./cftpipe.sh setupThis command will:
- Prompt you for your Cloudflare Account ID if not set via
CF_ACCOUNT_ID. - List your available domains (zones) and prompt you to select one.
- Create a new Cloudflare Tunnel.
- Save the tunnel configuration to
~/.cloudflared/tunnel-config.json.
Starts the Cloudflare Tunnel, exposing a local port to a public URL.
Usage:
./cftpipe.sh run [options]Options:
-p, --port <port>: Specify the local port to expose. If not provided, the script will attempt to detect a running service on common development ports. Defaults to3000if none are detected.-s, --name <slug>: Specify a custom subdomain (slug). If not provided, a unique slug will be generated (e.g.,myproject-123456-abcdef).-r, --reuse: Reuse the last known hostname for the current directory.
Examples:
- Autodetect port and generate a new hostname:
./cftpipe.sh run
- Specify a port:
or
./cftpipe.sh run -p 8080
./cftpipe.sh run 8080
- Specify a custom hostname:
This will create a tunnel at
./cftpipe.sh run -s my-cool-app
my-cool-app.yourdomain.com. - Reuse the previous hostname for the project:
./cftpipe.sh run -r
Deletes the DNS record for a given slug.
Usage:
./cftpipe.sh destroy <slug>Example:
./cftpipe.sh destroy my-cool-appThis will delete the CNAME record for my-cool-app.yourdomain.com. It will also ask if you want to delete the entire tunnel, which would affect all subdomains created with it.
Lists the 20 most recently created tunnels from your history.
Usage:
./cftpipe.sh listOutput format:
<timestamp> | <project> | https://<hostname> | port <port>
Displays the current tunnel configuration from ~/.cloudflared/tunnel-config.json.
Usage:
./cftpipe.sh statusDisplays the help message.
Usage:
./cftpipe.sh helpor
./cftpipe.sh -hor
./cftpipe.sh --help