ui

package
v0.10.9 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BrandingAssetHandler added in v0.5.4

func BrandingAssetHandler(allow map[string]string) http.Handler

BrandingAssetHandler serves ONLY the basenames in the allow-list. There is no path arithmetic on request input: the trailing segment is looked up in the map, so traversal, encoded segments and symlink tricks cannot escape.

func CSPInlineSources added in v0.8.29

func CSPInlineSources(p Public) (scriptSources, styleSources []string, err error)

CSPInlineSources returns the CSP source expressions for every inline <script> and <style> block in the shell RenderIndex emits for p: the static inline scripts baked into index.html plus the branding <script>/<style> RenderIndex injects. A strict Content-Security-Policy can then allow exactly those blocks instead of 'unsafe-inline'. The style slice is empty when no primary color is configured. Because it reuses the same builders/bytes RenderIndex serves, the hashes always match. (The branding-inactive path serves the raw shell and uses StaticShellInlineScriptSources alone - see cmd/shinyhub.)

func ExactUIRoutes added in v0.9.4

func ExactUIRoutes() []string

ExactUIRoutes is the single source of truth for the client-side SPA routes that are matched by an EXACT path (as opposed to the /apps/<slug> pattern). Both IsUIPath (the shell-fallback guard) and the server's mux registrations derive from this list so the two cannot drift - a route present in one but not the other silently 404s on deep links/reloads. To add an SPA page, add it here.

func Handler

func Handler() http.Handler

Handler returns an HTTP handler that serves the Static() FS rooted at /static/. Register it as mux.Handle("/static/", ui.Handler()).

Asset URLs are unversioned, so the handler sets a revalidation cache policy: a per-build content ETag plus Cache-Control: no-cache, letting browsers cache but revalidate (a matching If-None-Match yields a cheap 304), and refetch automatically when a new release changes the assets. In dev-static mode the files change on disk under a running server, so caching is disabled outright.

func IsUIPath added in v0.5.4

func IsUIPath(path string) bool

IsUIPath reports whether path is a client-side-rendered SPA route that should be served the index.html shell.

func RenderIndex added in v0.5.4

func RenderIndex(raw []byte, p Public) ([]byte, error)

RenderIndex injects branding into the stock SPA shell. Callers MUST only invoke this when branding is active; the zero-branding path serves raw bytes elsewhere and is never routed here.

func StampAuthenticated added in v0.8.12

func StampAuthenticated(shell []byte) []byte

StampAuthenticated marks the SPA shell as already-authenticated so the dashboard chrome paints immediately, skipping the boot splash and never flashing the login form. Callers invoke this only when the request that fetched the shell is itself authenticated (e.g. behind forward auth). It swaps the default data-auth="loading" for data-auth="in"; if the marker is absent (already stamped, or the shell changed), it returns the input unchanged.

func Static

func Static() fs.FS

Static returns the filesystem serving UI assets. If SHINYHUB_DEV_STATIC is set to a directory path, assets are served from disk so edits appear on page refresh without rebuilding the binary. Otherwise the compiled-in embed.FS is used.

func StaticShellInlineScriptSources added in v0.9.4

func StaticShellInlineScriptSources() ([]string, error)

StaticShellInlineScriptSources returns the CSP hash sources for the inline <script> blocks baked into the embedded index.html shell (e.g. the pre-paint theme bootstrap). These are served in EVERY deployment - branded or not - so a strict CSP must always allow them, independent of branding. Reading the shell that is actually served keeps the hashes from drifting from the served bytes.

Types

type Public added in v0.5.4

type Public struct {
	SiteTitle    string              `json:"site_title,omitempty"`
	Favicon      string              `json:"favicon,omitempty"`
	PrimaryColor string              `json:"primary_color,omitempty"`
	FooterLinks  []config.FooterLink `json:"footer_links,omitempty"`
}

Public is the small, documented branding object exposed inline in the SPA shell and at GET /.shinyhub/branding.json. URLs are browser-ready.

func PublicBranding added in v0.5.4

func PublicBranding(b config.BrandingConfig, resolved map[string]string) Public

PublicBranding builds the browser-ready object. resolved is the basename->path allow-list (nil when only URLs/scalars are used).

Jump to

Keyboard shortcuts

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