Vite: "Blocked request. This host is not allowed"
Tested with Vite 8.4,
Vite only answers requests addressed to hosts it trusts: localhost, *.localhost and IP addresses. A tunnel (ngrok, Cloudflare Tunnel and others) reaches Vite under its own hostname, so Vite refuses it. Add that hostname to server.allowedHosts in vite.config.js and restart Vite.
The message
Blocked request. This host ("abc123.trycloudflare.com") is not allowed.
To allow this host, add "abc123.trycloudflare.com" to `server.allowedHosts` in vite.config.js.
Under vite preview it names preview.allowedHosts instead.
The fix
// vite.config.js
export default {
server: {
allowedHosts: ['.trycloudflare.com'], // a leading dot also allows every subdomain
},
};
- Exact name or a domain.
'abc123.trycloudflare.com'allows one tunnel;'.trycloudflare.com'allows any, which helps when the random name changes on every start. allowedHosts: trueallows any host. Vite's docs warn that it lets any website send requests to your dev server through DNS rebinding, so prefer a list.- Frameworks on Vite pass it through: Angular
ng serve --allowed-hosts, Astroastro dev --allowed-hosts.
Why Vite does this
In January 2025 a vulnerability (CVE-2025-24010) showed that any website you visited could read your dev server through DNS rebinding. Vite 6.0.9, 5.4.12 and 4.5.6 added the host check, tightened the default CORS settings and protected the hot-reload WebSocket. The check is skipped over HTTPS, and IP addresses are always allowed, so it only bites tunnels and custom hostnames over plain HTTP.
Opening Vite on your phone
- Start Vite with
npx vite --host, or setserver: { host: true }. By default Vite listens only onlocalhost. - Open the Network address it prints, such as
http://192.168.1.20:5173, on a phone on the same Wi-Fi. The host check doesn't block IP addresses.
That address isn't a secure context, so the camera, microphone and crypto.subtle won't work on the phone. How to get HTTPS on the phone.
Hot reload through a tunnel
If the page loads through a tunnel but changes don't arrive, the browser may be trying to reach Vite's WebSocket on the wrong port. Point it at the tunnel's HTTPS port:
// vite.config.js (Vite 8.1+; older versions use server.hmr.clientPort)
export default {
server: { ws: { clientPort: 443 } },
};
Without editing the config
Tondavo opens your Vite server on the phone over HTTPS from a QR code and sends its requests to Vite as localhost. On Vite 8.4, the page and hot reload worked with the default config, with no --host and no allowedHosts. It also reaches Vite when Vite listens only on IPv6 ::1, as it did by default in our test on macOS. The phone's traffic passes through Tondavo's edge on Cloudflare; if it must stay on your network, use --host and the Wi-Fi address as above.
npx tondavo 5173
To try it: npx tondavo. See Getting started.