Cloudflare Tunnel for Local Development
Quick Setup
Section titled “Quick Setup”-
Install cloudflared
Download and install the Cloudflare Tunnel client (cloudflared) for your operating system -
Run a quick tunnel (no setup required)
Executecloudflared tunnel --url http://localhost:8787to instantly expose your local Worker (typically running on port 8787) -
Access via free domain
Cloudflare automatically generates a random subdomain likehttps://wise-juvenile-pink-recovered.trycloudflare.com
Using Your Own Domain (Optional)
Section titled “Using Your Own Domain (Optional)”If you want a custom domain instead of the random subdomain:
-
Authenticate - Run
cloudflared tunnel loginto authorize with your Cloudflare account -
Create named tunnel - Execute
cloudflared tunnel create mytunnelto generate a persistent tunnel with UUID -
Configure routing - Create
~/.cloudflared/config.ymlspecifying your tunnel ID, credentials file, and hostname mapping to localhost:port~/.cloudflared/config.yml tunnel: <TUNNEL_UUID>credentials-file: /path/to/credentials-file.jsoningress:- hostname: dev.yourdomain.comservice: http://localhost:8787- service: http_status:404 -
Set DNS record - Run
cloudflared tunnel route dns mytunnel dev.yourdomain.comto create the DNS entry -
Run tunnel - Execute
cloudflared tunnel run mytunnelto start the tunnel
Does Cloudflare Provide a Domain?
Section titled “Does Cloudflare Provide a Domain?”Yes - When you run the quick tunnel command without authentication, Cloudflare automatically generates a free trycloudflare.com subdomain for you. However, this is a random subdomain that changes each time.
If you want a permanent custom domain (like dev.yourdomain.com), you need to own a domain and use Cloudflare’s nameservers.