Documentation
¶
Overview ¶
Package webui serves an application's built single-page app from an fs.FS (the application embeds its own build).
It answers only the SPA's own paths: the client routes the application lists get index.html, so a reload of /account/passkeys or /consent?txn=… works; hashed assets under /assets/ are cached for a year; the static files at the top of the build (theme.js, the icons, the manifest) revalidate by ETag. Every other path is left to the packages that own it (/api, /oauth, /mcp, /.well-known, /healthz), so register the SPA next to them on the same mux: a conflict between two owners of one path panics at start, not in production.
Every answer carries the application's CSP, HSTS, X-Frame-Options, Referrer-Policy: no-referrer and nosniff (httpsec.SetSecurityHeaders). Cross-Origin-Opener-Policy is same-origin everywhere except on the routes the application names in Options.NoOpener: a page that runs inside an assistant's connector window (the consent page) would lose the window's tie to the assistant's page under COOP.
Index ¶
Constants ¶
const (
// DefaultNotBuilt is the 503 text of a binary without a build, when Options.NotBuiltHint is empty.
DefaultNotBuilt = "The web UI is not built into this binary."
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// FS is the build: index.html at its root, hashed assets under assets/, public files at the top (fs.Sub of an
// embed.FS). A build without index.html is "not built": the pages answer 503 and the assets 404.
FS fs.FS
// Routes are the client routes that answer index.html, as mux patterns without a method: "/" (the root page),
// "/login", "/account", "/account/{rest...}". List a subtree's root and its "/{rest...}" both.
Routes []string
// NoOpener are routes (entries of Routes) sent without Cross-Origin-Opener-Policy.
NoOpener []string
// CSP is the Content-Security-Policy of every answer (httpsec.DefaultCSP is a strict one).
CSP string
// NotBuiltHint is the 503 text when FS has no index.html, e.g. "run `make web`, then rebuild"; "" is
// DefaultNotBuilt.
NotBuiltHint string
// Logger says once whether a build was found; nil discards.
Logger *slog.Logger
}
Options configure the SPA handler.
type Routes ¶
type Routes struct {
// contains filtered or unexported fields
}
Routes serves one SPA build; it implements core.RouteRegistrar.
func (*Routes) RegisterRoutes ¶
RegisterRoutes adds GET (and so HEAD) for the client routes, the hashed assets and the public files.