Preview a local build
The scenario
You generated a static site or a front-end build — Hugo, Jekyll, Eleventy, vite build, create-react-app, Angular, Astro — and you want to look at the real output before shipping it. Opening index.html over file:// breaks absolute paths, routing and fetch calls. A dev server (vite dev, webpack serve) shows your source, not the artifact you are about to deploy.
servd serves the built directory over HTTP, exactly like a static host would.
One command
servd --static=./dist --port=3000
Open http://localhost:3000/. On startup servd prints what it resolved, so you can confirm the right folder is mounted:
servd 0.1.0 listening on 0.0.0.0:3000 (all IPv4 interfaces)
Hosts: unrestricted
static / -> /you/project/dist
What you get for free
- Directory indexes.
/docsredirects to/docs/and servesdocs/index.htmlwhen present, so relative links and canonical URLs stay stable. - Realistic caching. Files are served with
Cache-Control: no-cacheplus a weakETagandLast-Modified, so repeat loads return fast304 Not Modified— the behavior a CDN or origin would give you. - Compression. Pre-compressed
file.gz/file.brsiblings are served directly; otherwise compressible text is gzipped on the fly, with a correctVary: Accept-Encoding. - Path safety.
..,//, backslashes and NUL bytes are rejected, and files are opened through a rooted handle, so the server cannot be tricked into reading outside./dist.
Handy variations
Serve several folders and overlay them at one mount (first existing file wins):
servd --static=./dist --static=/assets=./public/assets --port=3000
Restrict which Host headers are answered, useful when a preview is reachable from the network:
servd --static=./dist --host=localhost --port=3000
If the output is a single-page app rather than a multi-page site, use --spa instead so client-side routes fall back to index.html.