Documentation
¶
Overview ¶
Package webui provides the embedded Next.js static export. Without the embed_frontend build tag, no frontend is included and the Go server only handles API routes (dev mode uses a separate `next dev` process on :3000).
Index ¶
- Constants
- func DefaultPrivacyMarkdown() []byte
- func DefaultTermsMarkdown() []byte
- func DistFS() (fs.FS, error)
- func FindPlaceholders(doc []byte) []string
- func IsEmbedded() bool
- func NewSPAHandler(opts ...Option) http.Handler
- func NewSPAHandlerFS(fsys fs.FS, opts ...Option) http.Handler
- func PolicyURLOK(raw string) bool
- func RenderPolicyPage(p PolicyPage) ([]byte, error)
- type Branding
- type Logo
- type Option
- type Options
- type PolicyPage
Constants ¶
const ( DefaultSiteName = "HTCondor" DefaultSiteTagline = "Access Point" )
Default presentation, matching what the frontend hard-codes.
const ( // PrivacyPath and TermsPath are where the pages are served. They // are fixed, so that an operator who has configured a policy has // one URL to give out -- to an OAuth2 provider's review form, say // -- whether the text is served from here or lives elsewhere. PrivacyPath = "/privacy" // TermsPath is the other of the pair. TermsPath = "/terms" // DefaultSource is the value of HTTP_API_WEBUI_PRIVACY_FILE or // HTTP_API_WEBUI_TERMS_FILE that selects the template this package // ships, instead of a path on disk. // // Opt-in rather than a fallback for an unreadable path: a site that // meant to serve its own policy and mistyped the path should find a // 404 and a warning in the log, not a template published under its // name. DefaultSource = "default" )
const CSSPath = "/branding.css"
CSSPath is where the site stylesheet is served, when there is one.
Variables ¶
This section is empty.
Functions ¶
func DefaultPrivacyMarkdown ¶ added in v0.26.0
func DefaultPrivacyMarkdown() []byte
DefaultPrivacyMarkdown and DefaultTermsMarkdown return the shipped templates. Copies, because the caller renders them and the embedded bytes are shared.
func DefaultTermsMarkdown ¶ added in v0.26.0
func DefaultTermsMarkdown() []byte
DefaultTermsMarkdown is the shipped terms-of-use template.
func FindPlaceholders ¶ added in v0.26.0
FindPlaceholders reports the template placeholders still present in a policy document.
Publishing a template with [CONTACT EMAIL] still in it is a mistake that nobody notices, because the page renders perfectly and the operator who configured it already knows what it was meant to say. The server cannot refuse to serve the document -- an operator may have reasons, and a missing privacy notice is its own problem -- so it says so in the log instead.
func IsEmbedded ¶
func IsEmbedded() bool
IsEmbedded reports whether the frontend is compiled into this binary.
func NewSPAHandler ¶
NewSPAHandler returns an http.Handler that serves the embedded frontend. It resolves Next.js static-export dynamic routes (e.g. [id] -> _) and falls back to index.html for client-side routing.
When the frontend is not embedded (no embed_frontend build tag), the returned handler responds with 404 so the caller can fall back to a non-SPA welcome page.
func NewSPAHandlerFS ¶
NewSPAHandlerFS serves a static export from an arbitrary fs.FS, with the same route resolution NewSPAHandler applies to the embedded frontend.
Site apps are served through this, from a zip bundle or from a directory rather than from embed.FS. That is what makes the path validation in serveFile load-bearing rather than belt-and-braces: embed.FS cannot reach anything outside the binary, and these filesystems can reach the real one.
func PolicyURLOK ¶ added in v0.26.0
PolicyURLOK reports whether a configured policy URL is one this UI will redirect to or put in an href: site-relative, or absolute http(s). Same rule, and the same reasons, as a configured logo.
func RenderPolicyPage ¶ added in v0.26.0
func RenderPolicyPage(p PolicyPage) ([]byte, error)
RenderPolicyPage renders one policy document as a standalone HTML page.
Standalone, and not a route in the single-page app, for three reasons: the page has to render for a reader with no JavaScript (an OAuth2 provider's reviewer may be one, and so is a crawler); it has to work before anybody has signed in; and it is the one part of this UI whose exact text matters legally, which is an argument for the server emitting it directly from the configured bytes rather than through a client-side renderer.
Types ¶
type Branding ¶
type Branding struct {
// SiteName is the sidebar heading, SiteTagline the line beneath it,
// and PageTitle the browser tab -- the two joined.
SiteName string `json:"site_name"`
SiteTagline string `json:"site_tagline"`
PageTitle string `json:"page_title"`
// Nil is the band the UI ships with (CHTC, Morgridge, UW-Madison);
// an empty list is no logos at all.
FooterLogos []Logo `json:"footer_logos"`
// SoftwareCredit asks the footer for its one-line "Powered by
// HTCondor" credit, naming the Center for High Throughput Computing.
// Set whenever the shipped logo band is not shown, so who wrote the
// software is still said on every page -- and distinguished from who
// runs the service, which is what the band above it says.
SoftwareCredit bool `json:"software_credit"`
// Favicon replaces the HTCondor mark in the browser tab.
Favicon string `json:"favicon,omitempty"`
// CustomCSS reports that this server serves a site stylesheet at
// /branding.css, loaded after the page's own.
CustomCSS bool `json:"custom_css,omitempty"`
// PrivacyURL and TermsURL are where the footer links for the site's
// policy pages point. Empty when the operator has configured none,
// and the footer then says nothing about them -- see policy.go.
//
// Normally PrivacyPath and TermsPath, served by this server. A site
// whose policy lives elsewhere (an institutional privacy notice,
// say) gets that URL here instead, so the footer link shows a
// reader where it is really going; the local path still redirects
// there, for whoever was given it.
PrivacyURL string `json:"privacy_url,omitempty"`
TermsURL string `json:"terms_url,omitempty"`
// Rev changes whenever anything above does. It busts the injected
// HTML cache and the stylesheet's URL after a reconfigure.
Rev uint64 `json:"-"`
}
Branding is the resolved presentation of one deployment's web UI.
func Build ¶
Build resolves configured values into a Branding.
Every part is independent, and a part that does not parse falls back to the shipped default rather than taking the rest of the branding down with it: a typo in the logo list should cost a site its logos, not its web UI. The error names every such fallback, for the caller to log.
func DefaultBranding ¶
func DefaultBranding() Branding
DefaultBranding is the presentation of an unconfigured deployment.
func (Branding) Inject ¶
Inject rewrites one exported HTML page to carry this branding.
Three edits, all inside <head>: the title, the favicon link, and a trailing block with the branding as a JavaScript global plus the site stylesheet. The stylesheet goes last on purpose -- it is loaded after the app's own, which is what lets a site redefine the --color-brand-* variables and recolour the whole UI.
A page with no </head> is returned untouched; there is no such page in the export, and guessing where to put the block would be worse than leaving the site unbranded.
type Logo ¶
type Logo struct {
// Src is the image URL: site-relative ("/branding/af.svg", normally
// something out of HTTP_API_WEBUI_BRANDING_DIR) or absolute http(s).
Src string `json:"src"`
// Alt is the text a screen reader reads and a broken image shows.
// Required: an unlabelled institutional logo tells a blind user
// nothing about who runs the service.
Alt string `json:"alt"`
// Href, when set, makes the logo a link.
Href string `json:"href,omitempty"`
}
Logo is one image in the footer's institutional band.
func ParseLogos ¶
ParseLogos reads the configured footer band.
Returns nil for an unset value -- the shipped band -- and a non-nil empty slice for "[]", which is a site saying it wants no logos.
type Option ¶
type Option func(*spaHandler)
An Option configures the SPA handler.
func WithBranding ¶
WithBranding gives the handler a source of site branding to splice into every HTML page it serves (see Branding.Inject). The function is called per request, so a reconfigure takes effect on the next page load; it may return the default branding, which injects nothing.
func WithHeadHTML ¶
WithHeadHTML splices a fixed block into the head of every HTML page this handler serves.
Unlike branding, which an operator can change at runtime, this block is constant for the life of the handler: a site app is told its id and mount point, and those are properties of the bundle that was loaded. A reloaded bundle gets a new handler.
type Options ¶
type Options struct {
SiteName string
SiteTagline string
// FooterLogos is a JSON array of {"src","alt","href"}. Empty keeps
// the shipped band; "[]" removes it.
Favicon string
// CustomCSS reports that HTTP_API_WEBUI_CUSTOM_CSS names a readable
// stylesheet. Resolving the path is the caller's job; this only
// decides whether the page links to it.
CustomCSS bool
// PrivacyURL and TermsURL are where the footer's policy links
// point, already resolved by the caller: empty for a site that has
// configured no such page. Validated here all the same, since they
// reach an href.
PrivacyURL string
TermsURL string
}
Options are the raw configured values, as they come out of the configuration file.
type PolicyPage ¶ added in v0.26.0
type PolicyPage struct {
// Title heads the page and names the browser tab, e.g. "Privacy
// Notice". The document's own first heading is kept as well; this
// is what the tab and the back-link say.
Title string
// SiteName is the deployment's name, for the tab title and the
// link back to the application.
SiteName string
// Markdown is the document, as configured.
Markdown []byte
// CustomCSS links the site stylesheet, so a deployment that has
// recoloured the UI gets a policy page that matches it.
CustomCSS bool
// Rev busts the stylesheet's cache, as elsewhere.
Rev uint64
}
PolicyPage is one rendered policy document.