Skip to content

Commit 837e5a2

Browse files
edmundhungMattieTK
andauthored
[Workers] update local dev tunnel guides and add changelog (#30822)
* docs(workers): add local dev tunnel guides and changelog * preview future chanelog * tighten changelog wording * link to access control and update demo gif * Clarify tunnel starting instructions in changelog Updated instructions for starting a tunnel and added details on named tunnels. --------- Co-authored-by: Matt ‘TK’ Taylor <matttaylor@cloudflare.com>
1 parent 05aeede commit 837e5a2

5 files changed

Lines changed: 84 additions & 21 deletions

File tree

332 KB
Loading
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Share local dev servers through Cloudflare Tunnel in Wrangler and Vite
3+
description: You can now share local dev servers through Cloudflare Tunnel from Wrangler and the Cloudflare Vite plugin, with support for quick tunnels and named tunnels.
4+
products:
5+
- workers
6+
date: 2026-05-18
7+
publish_future_dated_entry: true
8+
---
9+
10+
You can now share local dev sessions through [Cloudflare Tunnel](/tunnel/) and get a public URL when using either [Wrangler](/workers/wrangler/) or the [Cloudflare Vite plugin](/workers/vite-plugin/). This is useful when you need to share a preview, test a webhook, or access your app from another device.
11+
12+
![Vite local dev tunnel demo](~/assets/images/changelog/workers/vite-local-dev-tunnel.gif)
13+
14+
This lets you either:
15+
16+
- start a temporary [Quick tunnel](/tunnel/setup/#quick-tunnels-development) with a random `*.trycloudflare.com` hostname, or
17+
- use an existing [named tunnel](/tunnel/setup/#create-a-tunnel) for a stable hostname and to restrict access with [Cloudflare Access](/cloudflare-one/access-controls/).
18+
19+
To start a tunnel, press `t` in Wrangler or `t + Enter` in Vite while your dev server is running. For details on setting up a named tunnel, refer to [Share a local dev server](/workers/development-testing/local-dev-tunnels/).

src/content/docs/workers/development-testing/local-dev-tunnels.mdx

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,31 @@ description: Expose a local Wrangler or Vite dev server over a public tunnel URL
99

1010
import { PackageManagers, TypeScriptExample } from "~/components";
1111

12-
You can expose your local dev server over a [Cloudflare Quick Tunnel](/tunnel/setup/#quick-tunnels-development) when you need to share a preview, test a webhook, or access your app from another device. This provides a random `*.trycloudflare.com` hostname for the current dev session.
12+
You can expose your local dev server over a [Cloudflare Tunnel](/tunnel/) when you need to share a preview, test a webhook, or access your app from another device.
1313

1414
This page covers tunnel support in [Wrangler](/workers/wrangler/commands/general/#dev) and the [Cloudflare Vite plugin](/workers/vite-plugin/).
1515

1616
## Start a tunnel
1717

18+
You can start a tunnel with Wrangler or the Cloudflare Vite plugin for the current session. This gives you either a random `*.trycloudflare.com` hostname via a [Quick tunnel](/tunnel/setup/#quick-tunnels-development), or a stable hostname via a [named tunnel](/tunnel/setup/#create-a-tunnel).
19+
1820
**Wrangler**
1921

20-
Run `wrangler dev --tunnel`:
22+
Run `wrangler dev`, then press `[t]` to start or close the tunnel. Wrangler will print the public tunnel URL or URLs for the current session.
2123

22-
<PackageManagers type="exec" pkg="wrangler" args="dev --tunnel" />
24+
To use a named tunnel, run:
25+
26+
<PackageManagers type="exec" pkg="wrangler" args="dev --tunnel-name=my-tunnel" />
2327

24-
Wrangler will print the public tunnel URL for the current dev session.
28+
Use `--tunnel` if you want the tunnel to open automatically when Wrangler starts.
29+
30+
<PackageManagers type="exec" pkg="wrangler" args="dev --tunnel" />
2531

2632
**Cloudflare Vite plugin**
2733

28-
Enable `tunnel` conditionally in the plugin config:
34+
Run `vite dev`, then press `t + Enter` to start or close the tunnel. Add `tunnel` to the plugin config if you want to configure a named tunnel or have the tunnel open automatically when Vite starts.
35+
36+
To use a named tunnel with stable hostnames:
2937

3038
<TypeScriptExample filename="vite.config.ts">
3139
```ts
@@ -35,26 +43,44 @@ import { cloudflare } from "@cloudflare/vite-plugin";
3543
export default defineConfig({
3644
plugins: [
3745
cloudflare({
38-
tunnel: process.env.ENABLE_DEV_TUNNEL === "true",
46+
tunnel: { name: "my-tunnel" },
3947
}),
4048
],
4149
});
4250
```
4351
</TypeScriptExample>
4452

45-
Then enable the tunnel only for the sessions where you want a public URL:
53+
If you want the tunnel to open automatically when Vite starts, set `tunnel.autoStart` to `true`.
4654

47-
```sh
48-
ENABLE_DEV_TUNNEL=true vite dev # or "vite preview"
49-
```
55+
When using `vite preview`, Vite's preview host validation still applies:
56+
57+
- For Quick tunnel, add `.trycloudflare.com` to `preview.allowedHosts`.
58+
- For named tunnel, add the resolved hostnames or a matching domain suffix such as `.my-domain.com` to `preview.allowedHosts`.
5059

51-
Once the tunnel opens:
60+
For example:
5261

53-
- The public tunnel URL is printed in the terminal for the current dev session.
54-
- The session expires after 1 hour by default.
55-
- A reminder is logged every 10 minutes while the tunnel is open.
56-
- You can extend the tunnel by 1 hour at a time, either by pressing `t` for Wrangler or `t + Enter` for Vite.
57-
- The tunnel can be extended up to 3 hours of remaining time.
62+
<TypeScriptExample filename="vite.config.ts">
63+
```ts
64+
import { defineConfig } from "vite";
65+
import { cloudflare } from "@cloudflare/vite-plugin";
66+
67+
export default defineConfig({
68+
preview: {
69+
allowedHosts: [
70+
// For Quick tunnels:
71+
".trycloudflare.com",
72+
// For named tunnels:
73+
".my-domain.com"
74+
],
75+
},
76+
plugins: [
77+
cloudflare({
78+
tunnel: { name: "my-tunnel" },
79+
}),
80+
],
81+
});
82+
```
83+
</TypeScriptExample>
5884

5985
## Security considerations
6086

src/content/docs/workers/vite-plugin/reference/api.mdx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ products:
88
- workers
99
---
1010

11-
import { Type, MetaInfo } from "~/components";
11+
import { Type, MetaInfo, TypeScriptExample } from "~/components";
1212

1313
## `cloudflare()`
1414

@@ -76,9 +76,26 @@ It accepts an optional `PluginConfig` parameter.
7676

7777
See [Debugging](/workers/vite-plugin/reference/debugging/) for more information.
7878

79-
- `tunnel` <Type text='boolean' /> <MetaInfo text='optional' />
79+
- `tunnel` <Type text='boolean | { name?: string; autoStart?: boolean }' /> <MetaInfo text='optional' />
8080

81-
Open a publicly reachable Cloudflare Quick Tunnel for sharing a preview, testing webhooks, or accessing the app from another device.
81+
Expose your local dev server over a [Cloudflare Tunnel](/tunnel/).
82+
83+
Provide an object to configure a named tunnel or control whether the tunnel starts automatically. Press `t + Enter` to start or close the tunnel. Set `tunnel.autoStart` to `true` if you want the tunnel to open when Vite starts.
84+
85+
<TypeScriptExample filename="vite.config.ts">
86+
```ts
87+
import { defineConfig } from "vite";
88+
import { cloudflare } from "@cloudflare/vite-plugin";
89+
90+
export default defineConfig({
91+
plugins: [
92+
cloudflare({
93+
tunnel: { name: "my-tunnel" },
94+
}),
95+
],
96+
});
97+
```
98+
</TypeScriptExample>
8299

83100
See [Share a local dev server](/workers/development-testing/local-dev-tunnels/) for more information.
84101

src/content/docs/workers/wrangler/commands/workers.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ None of the options for this command are required. Many of these options can be
122122
- `--remote` <Type text="boolean" /> <MetaInfo text="(default: false) optional" />
123123
- Develop against remote resources and data stored on Cloudflare's network.
124124
- `--tunnel` <Type text="boolean" /> <MetaInfo text="(default: false) optional" />
125-
- Open a publicly reachable Cloudflare Quick Tunnel for sharing a preview, testing webhooks, or accessing the app from another device.
126-
- For more information, refer to [Share a local dev server](/workers/development-testing/local-dev-tunnels/).
125+
- Expose your local dev server over a Cloudflare Tunnel. For more information, refer to [Share a local dev server](/workers/development-testing/local-dev-tunnels/).
126+
- `--tunnel-name` <Type text="string" /> <MetaInfo text="optional" />
127+
- Use an existing named Cloudflare Tunnel. Combine with `--tunnel` to open it automatically at startup.
127128
- `--test-scheduled` <Type text="boolean" /> <MetaInfo text="(default: false) optional" />
128129
- Exposes a `/__scheduled` fetch route which will trigger a scheduled event (Cron Trigger) for testing during development. To simulate different cron patterns, a `cron` query parameter can be passed in: `/__scheduled?cron=*+*+*+*+*` or `/cdn-cgi/handler/scheduled?cron=*+*+*+*+*`.
129130
- `--log-level` <Type text="'debug'|'info'|'log'|'warn'|'error|'none'" /> <MetaInfo text="(default: log) optional" />

0 commit comments

Comments
 (0)