Cloudflare Tunnel: a quick URL and a stable domain
cloudflared is the package’s second provider. It needs the cloudflared executable on your PATH. The package never downloads it.
The provider has two modes. A Quick Tunnel gives a one-time address without an account. A named tunnel with a token gives a stable domain.
Quick Tunnel: a URL without an account
vkma-tunnel --provider cloudflared
# or in vite.config.ts: vkmaTunnel({ provider: "cloudflared" })- The address is one-time, of the form
https://<random-name>.trycloudflare.com, and it changes on every start. It suits opening the app from a phone. It does not suit the VK app settings. - The address may not answer for up to a minute. The package does not print it until it answers. If a minute has passed, the package prints the address without a check.
- The package stores nothing. Your
opentunnelprofile and identity are left alone. - Cloudflare limits Quick Tunnels: 200 in-flight requests, and the rest get a
429; Server-Sent Events do not work; availability is not guaranteed. - Anyone who has the link gets in.
Token: a stable domain
Create a named tunnel in the Cloudflare dashboard. Add a public hostname on your own domain and point it at http://localhost:<port>. Pass the token through an environment variable only.
export TUNNEL_TOKEN=… # the dashboard's token, keep it out of the command's arguments and out of files
vkma-tunnel --provider cloudflared --cloudflared-mode token --cloudflared-hostname app.example.comvkmaTunnel({
provider: "cloudflared",
cloudflared: { mode: "token", hostname: "app.example.com" },
});The package also reads the cloudflared.token config key. But vite.config.ts usually ends up in a repository, so keep the token in TUNNEL_TOKEN.
What to keep in mind in token mode:
- The dashboard sets the
Hostheader. The dashboard decides where the traffic goes, so the package cannot rewriteHost. Open the tunnel’s settings. Under Additional application settings, open HTTP and setHost headertolocalhost:<port>. Vite’sallowedHostsaccepts thatHost. Or add the hostname toserver.allowedHosts. When the package cannot rewriteHost, it prints a warning. - A profile belongs to one provider. The modes that store a record (opentunnel and token mode) refuse to run under another provider’s profile. Pick another
--profile. A Quick Tunnel stores nothing and runs under any profile. - The default transport is
http2. Where UDP 7844 is blocked,quicregisters and then dies every few seconds. You can enable it only explicitly, withcloudflared: { protocol: "quic" }.
The Host header
In Quick Tunnel mode cloudflared rewrites Host to localhost:<port> itself. Vite’s allowedHosts check passes without changes to your config, and HMR works.
If your server needs the real public Host, turn the rewrite off with hostRewrite: false (--no-host-rewrite in the CLI) and allow the suffix. The hostname is new every time, so a single hostname in allowedHosts will not help:
export default {
server: { allowedHosts: [".trycloudflare.com"] },
};Without that rule Vite answers 403 Blocked request. With it the page and HMR open.
Next
- OpenTunnel — the default provider with a stable address.
- CLI — the
--cloudflared-*flags. - Overview — the quick start and the rules common to both providers.