Documentation
¶
Overview ¶
Package web embeds the built frontend (web/dist) into the apptownd binary. Build the frontend first: cd web && npm run build (see Makefile).
Index ¶
Constants ¶
const EntryHeader = "X-AppTown-Web"
EntryHeader carries, on every response, the entry script of the page this AppTown serves. A tab opened on an earlier build compares it with the script it was loaded from and offers a reload when they differ: the data a tab polls refreshes by itself, its own code does not.
Variables ¶
var Dist embed.FS
var DistHandler = sync.OnceValue(func() http.Handler { sub, err := fs.Sub(Dist, "dist") if err != nil { return http.NotFoundHandler() } return Handler(sub) })
DistHandler serves the embedded build. Its file table (types, ETags, variants) is built once per process: the embedded bytes cannot change, and building it reads and hashes the whole bundle, which every App paid again.
var Entry = sync.OnceValue(func() string { b, err := Dist.ReadFile("dist/index.html") if err != nil { return "" } return entryIn(b) })
Entry is the embedded build's entry script, read once: the embedded bytes cannot change. Empty when no frontend was built into this binary.
Functions ¶
func Handler ¶
Handler serves a built single-page app from fsys: hashed assets are immutable, anything else is revalidated, the smallest variant the client accepts is chosen by Accept-Encoding, and an unknown path outside assets/ gets index.html so client-side routes load. Serving the compressed bytes from apptownd itself means compression and caching hold behind any proxy.
func ImageOrigins ¶
func ImageOrigins() []string
ImageOrigins returns the remote image origins allowed by AppTown's UI.
Types ¶
This section is empty.