|
1 | 1 | --- |
2 | | -last_modified: 2026-03-24 |
| 2 | +last_modified: 2026-05-14 |
3 | 3 | title: "Share your local server with Tunnel" |
4 | 4 | description: "Expose a public URL instantly with the --tunnel option" |
5 | 5 | url: /examples/tunnel_tutorial/ |
@@ -78,34 +78,52 @@ Deploy console. |
78 | 78 |
|
79 | 79 | ## Tunnel to your local server |
80 | 80 |
|
81 | | -The tunnel feature is built into the Deno CLI. It unlocks some of the powerful |
82 | | -features of Deno deploy, but for your local server! |
| 81 | +The `--tunnel` flag is built into the Deno CLI. It opens a secure HTTPS tunnel |
| 82 | +from a public Deno Deploy URL to the server running on your local machine, so |
| 83 | +requests arrive at your local process as if it were the deployed application. |
| 84 | +The public URL is tied to the Deploy project you created in the previous step; |
| 85 | +it stays the same every time you restart the tunnel, which makes it safe to |
| 86 | +paste into a webhook config or share with a teammate without having to hand out |
| 87 | +a new URL each session. |
83 | 88 |
|
84 | | -To start a tunnel to your local server, run the following command in your |
85 | | -project directory: |
| 89 | +`--tunnel` is available on any subcommand that runs a long-running server, so |
| 90 | +you can pair it with `deno run`, `deno task`, or `deno serve`. In this tutorial |
| 91 | +we're tunneling the Svelte `dev` task: |
86 | 92 |
|
87 | 93 | ```sh |
88 | 94 | deno run --tunnel dev |
89 | 95 | ``` |
90 | 96 |
|
91 | | -If redirected to the browser, authenticate with your Deno Deploy account. |
| 97 | +The first time you run this, your browser will open so you can authenticate with |
| 98 | +your Deno Deploy account; subsequent runs reuse the cached credentials. After a |
| 99 | +few moments you should see output similar to this: |
92 | 100 |
|
93 | | -This command will start your local server and create a secure tunnel to it. |
94 | | -After a few moments, you should see output similar to this: |
95 | | - |
96 | | -```sh |
| 101 | +```console |
97 | 102 | ➜ Local: http://localhost:5173/ |
98 | 103 | ➜ Network: use --host to expose |
99 | 104 | ➜ press h + enter to show help |
100 | 105 | You are connected to https://my-app-name.myusername.deno.net |
101 | 106 | ``` |
102 | 107 |
|
103 | | -That public url (`https://my-app-name.myusername.deno.net` in this example) is |
104 | | -now accessible from anywhere on the internet! You can share this URL with others |
105 | | -to access your local Svelte app, (much like ngrok or other tunneling services). |
| 108 | +That public URL (`https://my-app-name.myusername.deno.net` in this example) is |
| 109 | +now accessible from anywhere on the internet: share it with a colleague, point a |
| 110 | +webhook at it, or open it from your phone on a different network to test mobile |
| 111 | +layouts. Changes you make to your local code are reflected at the public URL in |
| 112 | +real time, just like local development. |
| 113 | + |
| 114 | +To stop the tunnel, press `Ctrl+C` in the terminal. The public URL goes offline |
| 115 | +until you start the tunnel again. The deployed version of the project on Deno |
| 116 | +Deploy is not affected, `--tunnel` only redirects traffic for as long as the |
| 117 | +local command is running. |
| 118 | + |
| 119 | +:::tip |
| 120 | + |
| 121 | +If you want to expose a different local port (for example a backend on |
| 122 | +`localhost:8000` rather than the Vite dev server), run `deno serve --tunnel` |
| 123 | +against the file that listens on that port. The tunnel always forwards to the |
| 124 | +server the Deno command starts. |
106 | 125 |
|
107 | | -You can make changes to your local code as normal, and the changes will be |
108 | | -reflected at the public URL in real-time. |
| 126 | +::: |
109 | 127 |
|
110 | 128 | ## Configuring environment variables |
111 | 129 |
|
|
0 commit comments