> ## Documentation Index
> Fetch the complete documentation index at: https://docs.layercode.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a Cloudflare tunnel for webhooks

> Expose your local backend to Layercode using Cloudflare Tunnel.

<Note>
  Layercode needs to send a webhook to your backend to generate agent responses. If you're running your backend locally, you'll need to expose it to the internet using a tunnel service.
</Note>

## Setting up a tunnel with cloudflared

We recommend using [cloudflared](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/do-more-with-tunnels/trycloudflare/), which is free for development.

<Steps>
  <Step title="Install cloudflared">
    * **macOS:** `brew install cloudflared`
    * **Windows:** `winget install --id Cloudflare.cloudflared`
    * [Other platforms](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/)
  </Step>

  <Step title="Start the tunnel">
    Run the following command to expose your local server:

    ```bash theme={null}
    cloudflared tunnel --url http://localhost:YOUR_PORT
    ```
  </Step>

  <Step title="Copy your tunnel URL">
    After starting, cloudflared will print a public URL in your terminal, e.g.:

    ```
    https://my-tunnel-name.trycloudflare.com
    ```

    Add the path of your backend's webhook endpoint to the URL, e.g.:

    ```
    https://my-tunnel-name.trycloudflare.com/api/agent
    ```

    `/api/agent` is just an example. Your actual endpoint may be different depending on your backend configuration.
  </Step>

  <Step title="Update your Layercode agent">
    1. Go to the [Layercode dashboard](https://dash.layercode.com).
    2. Click on your agent.
    3. Click the Edit button in the 'Your Backend' box.
    4. Enter your Webhook URL (from the previous step) and ensure your `LAYERCODE_WEBHOOK_SECRET` matches your environment variable.
  </Step>

  <Step title="Test your agent">Open the agent Playground tab and start speaking to your voice agent!</Step>

  <Step title="Troubleshooting">
    If you're having trouble, make sure your backend server is running and listening on the specified port (e.g., 3000). You can also visit the Webhook Logs tab in the agent to see the webhook requests being sent and any errors returned.
  </Step>
</Steps>

<Warning>
  Every time you restart the cloudflared tunnel, the assigned public URL will change. Be sure to update the webhook URL in the Layercode dashboard each time you restart the tunnel.
</Warning>

## Alternative Tunneling Solutions

Besides cloudflared, you can also use other tunneling solutions like [ngrok](https://ngrok.com/) to expose your local backend.

## If using Vite:

By default, Vite blocks requests from other hosts, so you will need to add your Cloudflared (or ngrok, etc.) address to `vite.config.ts` in `server.allowedHosts`.

For example:

```ts theme={null}
allowedHosts: ["suggesting-sri-pair-hugh.trycloudflare.com"]
```
