webui

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

func New(o Options) (*Routes, error)

New reads the build in o.FS and validates the options.

func (*Routes) RegisterRoutes

func (rt *Routes) RegisterRoutes(mux *http.ServeMux)

RegisterRoutes adds GET (and so HEAD) for the client routes, the hashed assets and the public files.

Jump to

Keyboard shortcuts

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