# Cloudflared

Source: https://docs.sliplane.io/private-networking/cloudflared

Set up Cloudflare Tunnel with cloudflared to expose private Sliplane services without opening inbound ports.

[Cloudflared](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/) is the client for Cloudflare Tunnel. It runs next to your private services, creates an outbound tunnel to Cloudflare, and lets Cloudflare route traffic to your services without exposing public ports on Sliplane.

## Prerequisites

* A [Cloudflare account](https://dash.cloudflare.com/)
* A domain added to Cloudflare
* A Sliplane server with private services you want to expose

## Step 1: Get Your Cloudflare Tunnel Token

1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/)
2. Go to **Networking** > **Tunnels**
3. Click **Create Tunnel**
4. Give your tunnel a name and click **Create Tunnel**
5. Select **Docker**
6. Copy the token from the install command

The token is the long string after `--token` in the Docker command.

## Step 2: Deploy Cloudflared on Sliplane

Use the Cloudflared preset to create the service:

[Deploy Cloudflared](https://sliplane.io/app/deploy?presetId=cloudflared)

Before deploying, replace the placeholder for environment variable `TUNNEL_TOKEN` with the token from Step 1.

After deployment, go back to the Cloudflare dashboard. The tunnel should show as **Healthy** within a few seconds.

## Step 3: Add a Published Application

In the Cloudflare dashboard:

1. Go to **Networking** > **Tunnels**
2. Click your tunnel
3. Open the **Routes** tab
4. Click **Add route** > **Published application**
5. Set the **Subdomain** and **Domain** you want to use
6. Set the **Service URL** to your Sliplane service's internal hostname and port

For example, if your private service is called `my-service` and listens on port `3000`, use:

```text
http://my-service.internal:3000
```

Cloudflared can reach private Sliplane services on the same server through their `.internal` hostnames.

## Step 4: Access Your Service

Once the route is saved, open the domain you configured in Cloudflare:

```text
https://app.example.com
```

## Troubleshooting

**Tunnel disconnected:**

* Make sure the status of the tunnel is `Healthy` in the Cloudflare dashboard
* Verify that `TUNNEL_TOKEN` is set correctly
* Check the service logs in Sliplane

**Requests are not reaching your service:**

* Verify the internal hostname and port in the Cloudflare route
* Make sure the target service is running on the **same** Sliplane server
* Confirm that the target service is listening on the port you configured

**Route works locally but not through Cloudflare:**

* Check that your domain is active in Cloudflare
* Verify that the published application uses the right hostname
* Review Cloudflare Access rules if you enabled access policies

See [Cloudflare Tunnel Troubleshooting](https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/troubleshoot-tunnels/) for more help.
