Skip to content
go-zooxPublic

About

A HTTP Static Server for Frontend, make you works with SPA easier.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

serve

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

Usage

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/html

SPA behaviour

serve 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 with index.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 with 200 text/html makes browsers refuse it and shows a blank page.
  • Cache policy — the SPA document is served with Cache-Control: no-cache (revalidated on every navigation, 304 while unchanged), content-hashed build output with Cache-Control: public, max-age=31536000, immutable.
  • /health returns OK for probes.

Read docs/spa-hosting.md for the exact rules, the rationale and how to verify a deployment.

Development

GOWORK=off go build ./...
GOWORK=off go vet ./...
GOWORK=off go test ./server/ -v      # end to end tests over real HTTP

GOWORK=off is needed when the checkout lives inside the go-zoox workspace, which does not list this module.

About

A HTTP Static Server for Frontend, make you works with SPA easier.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages