Skip to content

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 4321

The 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.

Start free:
or sign up with email

Astro at a glance

Dev server
npm run dev, port 4321
Share it
whk share 4321
Setting to add
None for whk share. server.allowedHosts is checked against Host, which arrives as localhost:4321.
Without it
Nothing through whk share. Other tunnels get 403 and Blocked 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.url is a localhost URL in dev. security.allowedDomains lets Astro take the host and scheme from X-Forwarded-Host and X-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

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

All 14 framework guides

Send someone your Astro app

Sign up free, install the CLI and run whk share 4321.

or sign up with email

No credit card