Documentation
¶
Overview ¶
Package web serves the built React UI, injecting the per-install token so the UI can call the authenticated API (§15). The dist/ directory is embedded.
dist/ is committed (a placeholder index.html when the real UI has not been built) so that go build/test/install work from a clean checkout with no Node toolchain: //go:embed requires the directory to exist at compile time. `make build` overwrites it with the real Vite output.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func APIReferencePage ¶
APIReferencePage returns the built api-reference.html — the standalone Scalar page Vite emits as its second entry point (web/api-reference.html).
It is a separate document from the SPA on purpose: @scalar/api-reference is a Vue 3 application, so mounting it inside the React app would ship a second framework runtime to everyone who opens the UI. A separate entry point keeps it code-split, and the daemon serves it at /api-reference (see internal/daemon/apidocs.go) because the SPA is hash-routed and has no history fallback.
ok is false in two different situations, which callers must be able to tell apart — see BuildState.
Unlike index.html this page carries no token: it is a plain static document that fetches /openapi.yaml, which needs no credential.
func Handler ¶
Handler returns an http.Handler that serves the embedded UI. The token is injected into index.html so the same-origin UI can authenticate API calls.
func HandlerFor ¶ added in v0.7.0
HandlerFor is Handler with the token decided per request. The daemon hands the token only to a browser provably on this machine; a remote one gets an empty token and signs in with a pairing code instead (internal/daemon, uisession.go), so the same page serves both.
Types ¶
type BuildState ¶
type BuildState int
BuildState describes which parts of the web UI this binary was built with.
const ( // BuildComplete: both the SPA and the API reference are embedded. BuildComplete BuildState = iota // BuildWithoutReference: the UI was built, but without the API reference // entry — an `APIDOCS=0 make build`, which trades the reference's ~3.7 MiB // for a smaller binary and expects the reference to be hosted elsewhere. BuildWithoutReference // BuildWithoutUI: the UI was never built. dist/ is gitignored apart from a // committed index.html placeholder, so this is what a fresh checkout that // has only run `go build` looks like. BuildWithoutUI )
func State ¶
func State() BuildState
State reports how this binary was built.
The distinction matters because the two absences need opposite advice: a checkout that never ran `make build` should run it, while an APIDOCS=0 build already did — telling its operator to "run make build" would be false, which is what the single boolean this replaces led the fallback page to say.
It is inferred from what is embedded rather than stamped at build time: the SPA's own index.html is the marker. A real build overwrites the committed placeholder with a document that loads a hashed asset bundle; the placeholder does not.