deserved
v0.9.0
Published
A tiny Bun static file server: SPA, live reload, zero dependencies.
Readme
deserved
A tiny Bun static file server: SPA, live reload, zero dependencies.
deserved serves a folder over HTTP with one command and no config:
clean URLs, an SPA fallback, ETags, ranges, and zstd or gzip.
With --watch, editing a page reloads it in the browser,
and editing a stylesheet swaps it in place.
When port 3000 is taken, it takes the next free one and says so.
That's a two-file page under --watch, loaded in a browser,
edited twice, then stopped with Ctrl-C.
Each request is one line: its status, then its path.
It runs on Bun ≥ 1.4.
Quick start
bun add -d deservedFor a one-off run with no install, bunx deserved <dir> fetches it.
bunx deserved dist --spa # serve dist/ at http://localhost:3000Exit status: 130 when Ctrl-C stops it, 143 for SIGTERM,
1 when the folder or the port fails, 2 when called wrong.
A mistyped option names the real
one: Unknown option: --hlep (did you mean --help?).
Common tasks
# Serve the current folder
deserved .
# A single-page app: a route with no file gets index.html
deserved dist --spa
# Reload the browser on every save, and open it
deserved site --watch --open
# Another port; one you name fails when taken, and never hops
deserved dist --port 8080
# Reachable from a phone on the same network
deserved dist --host 0.0.0.0
# A production build: hashed files cached for good, the rest revalidated
deserved dist --cache
# Fetched from a page on another origin
deserved dist --cors
# No request log
deserved dist --quietThe log is plain text when piped, under NO_COLOR,
or when a coding agent runs it; there's no --json,
since a server prints no data.
These docs ship in the package, at node_modules/deserved/docs/.
From code
import { serve } from "deserved";
const server = await serve({ root: "dist", port: 0, quiet: true });
console.log(server.url); // http://localhost:<a free port>
await server.stop();Docs
- CLI: every option, how the port is picked, the log, and the exit codes
- API:
serve(),createHandler()inside your ownBun.serve(), the options and the errors - How it works: how a URL finds a file, the SPA fallback, caching, compression, live reload, and what it never serves
