Lightweight, high performance HTTP server for frontends: static files, SPA fallback and reverse proxy in one binary.
Published as whatwewant/serve:v1 (registry.ys.zcorky.com/whatwewant/serve:v1).
serve -p 8080 -d /var/www/html --prefix /| Flag | Env | Default | Description |
|---|---|---|---|
-p, --port |
PORT |
8080 |
Port to listen on |
-d, --dir |
DIR |
current directory (/var/www/html in the image) |
Directory to serve |
--prefix |
PREFIX |
/ |
Path prefix to serve under |
--enable-gzip |
ENABLE_GZIP |
false |
Enable gzip compression |
--basic-auth |
BASIC_AUTH |
user:pass,user2:pass2 |
|
--api |
API |
Proxy /api (see --api-path) to a backend |
|
--api-path |
API_PATH |
/api |
Prefix of the proxied API |
--rewrite-api-path |
REWRITE_API_PATH |
false |
Strip the API prefix before proxying |
Docker:
FROM registry.ys.zcorky.com/whatwewant/serve:v1
COPY --from=build /build/dist /var/www/htmlserve is built for single page applications, in particular for ones using the
HTML5 browser history API:
- Browser history fallback — any navigation (
Accept: text/html) is answered withindex.html, whatever the route looks like, so deep links survive reloads. - Missing static assets are a real 404 —
/assets/**,*.js,*.css,*.png,*.jpeg, … never fall back to the document. Answering a module script with200 text/htmlmakes browsers refuse it and shows a blank page. - Cache policy — the SPA document is served with
Cache-Control: no-cache(revalidated on every navigation,304while unchanged), content-hashed build output withCache-Control: public, max-age=31536000, immutable. /healthreturnsOKfor probes.
Read docs/spa-hosting.md for the exact rules, the rationale and how to verify a deployment.
GOWORK=off go build ./...
GOWORK=off go vet ./...
GOWORK=off go test ./server/ -v # end to end tests over real HTTPGOWORK=off is needed when the checkout lives inside the go-zoox workspace,
which does not list this module.