Help us shape the future of Go! Take the 2026 Go Developer Survey

web

package
v1.0.0-rc.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

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

View Source
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

View Source
var Dist embed.FS
View Source
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.

View Source
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

func Handler(fsys fs.FS) http.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.

func WithEntry

func WithEntry(next http.Handler) http.Handler

WithEntry names the embedded build's entry script on every response.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL