vkma.devRU

@vkma.dev/tunnel — public HTTPS tunnels to a local server

On this page

@vkma.dev/tunnel gives a local dev server a public HTTPS address. You can open your build on a phone or hand the link to a colleague, and nothing gets deployed. The package has three entry points: a Vite plugin, the vkma-tunnel CLI and a Node API. It has two providers:

Provider Address What it needs
opentunnel (default) stable, https://<id>.opentunnel.xyz nothing: no account, the key stays on your machine
cloudflared one-time *.trycloudflare.com, or stable on your own domain the cloudflared executable, plus a Cloudflare account for the stable one

Quick start

The Vite plugin takes no options:

TSvite.config.ts
import { vkmaTunnel } from "@vkma.dev/tunnel/vite";

export default {
    plugins: [vkmaTunnel()],
};
npm install -D @vkma.dev/tunnel
npm run dev
pnpm add -D @vkma.dev/tunnel
pnpm dev
yarn add -D @vkma.dev/tunnel
yarn dev
bun add -D @vkma.dev/tunnel
bun run dev

The plugin reads the dev server’s actual listening port, starts the tunnel and prints its URL next to Vite’s own lines:

  ➜  Local:   http://localhost:5173/
  ➜  tunnel  →  https://4bznf5jcbkct.opentunnel.xyz  (profile my-app · localhost:5173)

The plugin works the same with vite preview. You can open a production build on a phone without deploying it.

Requests reach Vite without changes to your config. The package rewrites the Host header to an address Vite always accepts. HMR works through the tunnel. If the tunnel dies, the dev server keeps running and a red line appears in the terminal.

Options (all optional): enabled, config, provider, profile, qr, open, keepAlive, hostRewrite, and a provider’s section, opentunnel or cloudflared, with the keys it has in the config file. The plugin tunnels the server it is attached to.

Worth knowing

  • The URL is public. Anyone who has the link reaches your dev server. opentunnel and the Cloudflare Quick Tunnel have no authentication. If a URL leaks, run vkma-tunnel reset.
  • Stopping Vite closes the tunnel. This happens on Ctrl+C, on q and on SIGTERM. The service releases the route at once. Without it the next run would hit a route_conflict error.
  • Vite answers “Blocked request” to a foreign Host header. By default the package rewrites the header for you. Turn the rewrite off only if your server needs the real public Host. Then pass hostRewrite: false (--no-host-rewrite in the CLI) and add the address to server.allowedHosts. A new opentunnel profile gets its address only after the server has started. It then needs one more restart, and the plugin says so.

Next

  • OpenTunnel — the default provider: a stable address and the profile.
  • Cloudflare Tunnel — a one-time address without an account or a stable domain.
  • CLI — the vkma-tunnel commands and flags.
  • Configuration — the vkma-tunnel.config.* file and the priority of settings.
  • Node API — createTunnel for scripts and builds.
vkma.dev
RU
Esc