Skip to content

keskinonur/cloudflare-tunnel-pipe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

CFTPIPE Usage Documentation

cftpipe.sh is a command-line tool for managing Cloudflare Tunnels, allowing you to easily expose local web servers to the internet.

Prerequisites

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.

Environment Variables

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"

Commands

The script supports the following commands:

setup

Initializes the Cloudflare Tunnel configuration. This command only needs to be run once.

Usage:

./cftpipe.sh setup

This command will:

  1. Prompt you for your Cloudflare Account ID if not set via CF_ACCOUNT_ID.
  2. List your available domains (zones) and prompt you to select one.
  3. Create a new Cloudflare Tunnel.
  4. Save the tunnel configuration to ~/.cloudflared/tunnel-config.json.

run

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 to 3000 if 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:
    ./cftpipe.sh run -p 8080
    or
    ./cftpipe.sh run 8080
  • Specify a custom hostname:
    ./cftpipe.sh run -s my-cool-app
    This will create a tunnel at my-cool-app.yourdomain.com.
  • Reuse the previous hostname for the project:
    ./cftpipe.sh run -r

destroy

Deletes the DNS record for a given slug.

Usage:

./cftpipe.sh destroy <slug>

Example:

./cftpipe.sh destroy my-cool-app

This 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.

list

Lists the 20 most recently created tunnels from your history.

Usage:

./cftpipe.sh list

Output format:

<timestamp> | <project> | https://<hostname> | port <port>

status

Displays the current tunnel configuration from ~/.cloudflared/tunnel-config.json.

Usage:

./cftpipe.sh status

help

Displays the help message.

Usage:

./cftpipe.sh help

or

./cftpipe.sh -h

or

./cftpipe.sh --help

About

An easy usage for Cloudflare Tunnel with your own domain name with random slug

Topics

Resources

Stars

Watchers

Forks

Languages