Skip to content

Quickly Test Your Webhooks with Cloudflare Tunnel

Published: at 12:53 PM

Cloudflare Tunnel is tunneling software that lets you quickly secure and encrypt application traffic to any type of infrastructure. This enables you to hide your web server IP addresses, block direct attacks, and focus on delivering great applications.

Cloudflare Tunnel

Creating a tunnel between your local machine and a tunnel service exposes local ports to the public internet. Many tools can help you do this, but today you’re going to learn about Cloudflare Tunnel, also known as cloudflared (formerly Argo Tunnel).

Set up a Local Web Server

To get started, set up a local web server. You can use Python’s built-in HTTP server for this purpose:

python -m http.server 8080

This command will start a web server on port 8080.

Quickly Expose Your Local Web Server to the Internet

Next, install Cloudflare Tunnel. The installation process varies depending on your operating system.

For macOS:

brew install cloudflared

For Windows:

winget install --id Cloudflare.cloudflared

After installation, use the following command to create a tunnel that exposes your local server to the internet:

cloudflared tunnel --url http://localhost:8080

You will receive a message similar to the one below, providing you with a temporary URL to access your local server:

Thank you for trying Cloudflare Tunnel....
+--------------------------------------------------------------------------------------------+
|  Your quick Tunnel has been created! Visit it at (it may take some time to be reachable):  |
|  https://colleagues-ga-eternal-recruitment.trycloudflare.com                               |
+--------------------------------------------------------------------------------------------+
...

Use a Persistent Address for Your Cloudflare Tunnel

For more stability and convenience, you might want to use a persistent address. Here’s how to set it up:

  1. Log in to Cloudflare Tunnel:

    cloudflared tunnel login
    
  2. Create a Tunnel:

    cloudflared tunnel create test
    
  3. List Tunnels:

    cloudflared tunnel list
    
  4. Configure the Tunnel:

    Create or edit the configuration file at ~/cloudflared/config.yml:

    tunnel: <uuid>
    credentials-file: /Users/yourname/.cloudflared/<uuid>.json
    
    ingress:
      - hostname: test.myhost.com
        service: http://localhost:8080
      - service: http_status:404
    
  5. Run the Tunnel:

    cloudflared tunnel run
    

By following these steps, you can set up a persistent and secure tunnel for your local web server. This is particularly useful for testing webhooks or any application that requires a public endpoint.