Share localhost / Astro
Share an Astro dev server at a public URL
astro dev serves your site on localhost:4321, and whk share 4321 gives it an HTTPS link. Static pages, on-demand pages and HMR work without configuration. One optional setting makes Astro aware of the public address.
# terminal 1: the dev server
npm run dev
# terminal 2: the link
whk share 4321The link is https://<name>.sharehooks.cc and works until you press Ctrl-C. No whk yet? Install it and log in, which takes a minute.
Astro at a glance
- Dev server
npm run dev, port 4321- Share it
whk share 4321- Setting to add
- None for
whk share.server.allowedHostsis checked againstHost, which arrives aslocalhost:4321. - Without it
- Nothing through
whk share. Other tunnels get403andBlocked request. This host ("<host>") is not allowed. - Hot reload
- Yes. It is Vite's HMR on the dev server's own port, and the client connects to the host the page came from.
- URLs and cookies
Astro.urlis alocalhostURL in dev.security.allowedDomainslets Astro take the host and scheme fromX-Forwarded-HostandX-Forwarded-Proto.
Your dev server gets each request with Host: localhost:4321; the public name travels in X-Forwarded-Host, with X-Forwarded-Proto: https. What your server sees has the rest.
server.allowedHosts and astro dev
Astro passes server.allowedHosts to Vite, which answers localhost, names under .localhost and IP addresses, and refuses any other Host with 403 and Blocked request. This host ("<host>") is not allowed. Through whk share the dev server gets Host: localhost:4321, so the default, an empty list, is enough.
For a proxy that passes its public hostname on, the setting goes in astro.config.mjs, or on the command line as --allowed-hosts. It applies to astro dev and astro preview alike:
astro.config.mjs
import { defineConfig } from "astro/config";
export default defineConfig({
server: {
// Not needed for whk share; for proxies that send the public Host
allowedHosts: [".sharehooks.cc"],
},
});Forms and security.checkOrigin
For pages rendered on demand in a project built for a server (one with an adapter), Astro checks that form posts come from the same site (security.checkOrigin, on by default). It reads the browser's Sec-Fetch-Site header first, and a form on a shared page posting to the same link is same-origin, so it passes even though Astro itself believes it is on localhost.
The fallback is where a share can trip. A client that sends no Sec-Fetch-Site header (a script, an old browser) is judged by its Origin, compared with the URL Astro derived from Host: https://<name>.sharehooks.cc against http://localhost:4321. That post gets 403 and Cross-site POST form submissions are forbidden.
Make Astro.url the public address
In dev Astro.url is a localhost URL: Astro builds it from the Host header and ignores X-Forwarded-Host unless you allow the domain. With security.allowedDomains, a forwarded host that matches a pattern is used, along with the forwarded scheme:
astro.config.mjs
import { defineConfig } from "astro/config";
export default defineConfig({
security: {
// Trust X-Forwarded-Host for previews opened with whk share
allowedDomains: [{ hostname: "**.sharehooks.cc", protocol: "https" }],
},
});**.sharehooks.cc matches every name under the domain, so every preview; with a reserved name, write that name out instead. Astro.url and request.url then read https://<name>.sharehooks.cc/..., and the origin check compares like with like, for every client. A forwarded host outside the list is ignored. The site option is a different thing: it is your deployed URL, used for canonical links and the sitemap in a build.
Astro questions
Not with whk share: the dev server receives Host: localhost:4321, which is always allowed. With a tunnel that passes its public hostname as Host, add it to server.allowedHosts in astro.config.mjs, for example [".example.com"], or pass --allowed-hosts.
security.checkOrigin found a form post whose origin differs from the URL Astro thinks it is served from. Behind a proxy, add the public domain to security.allowedDomains so Astro takes its host from X-Forwarded-Host. Browsers that send Sec-Fetch-Site: same-origin pass the check without it.
Yes. Astro uses Vite's HMR on the same port as the site, and the client opens its WebSocket to the host the page was loaded from, so whk share carries it.
4321 by default. If it is in use, Astro tries the next available port, so share the port it prints. server.port in the config or --port on the command line sets another.
Sources
The Astro settings and messages on this page are from the official documentation and source for Astro 7.4, read on 12 November 2026. What the link does to a request is from the whk share docs.
Other frameworks
Send someone your Astro app
Sign up free, install the CLI and run whk share 4321.
No credit card