Skip to content

TunnelWrite

Source: src/Cloudflare/Tunnel/TunnelWrite.ts

Binding that lets a Worker create, update, and delete Cloudflare Tunnels at runtime.

Creates a scoped {@link AccountApiToken} with only the Cloudflare Tunnel Write permission and binds its outputs into the Worker (the token value as a secret_text binding) so runtime code can authenticate.

Bind the write client

Bind once in the Init phase; every method is available on the returned client.

const tunnels = yield* Cloudflare.TunnelWrite.bind();

Create a tunnel

const tunnel = yield* tunnels.create({ name: "on-demand-tunnel" });

Push ingress configuration

yield* tunnels.putConfiguration(tunnel.id!, {
ingress: [
{ hostname: "app.example.com", service: "http://localhost:3000" },
{ service: "http_status:404" },
],
});

Rename and delete a tunnel

yield* tunnels.update(tunnel.id!, { name: "renamed-tunnel" });
yield* tunnels.delete(tunnel.id!);

Provide {@link TunnelWriteLive} in the Worker’s runtime layer.

Effect.provide(Cloudflare.TunnelWriteLive)