Documentation
¶
Index ¶
- func BrandingAssetHandler(allow map[string]string) http.Handler
- func CSPInlineSources(p Public) (scriptSources, styleSources []string, err error)
- func ExactUIRoutes() []string
- func Handler() http.Handler
- func IsUIPath(path string) bool
- func RenderIndex(raw []byte, p Public) ([]byte, error)
- func StampAuthenticated(shell []byte) []byte
- func Static() fs.FS
- func StaticShellInlineScriptSources() ([]string, error)
- type Public
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BrandingAssetHandler ¶ added in v0.5.4
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
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 ¶
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
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
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
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 ¶
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
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"`
Logo string `json:"logo,omitempty"`
Favicon string `json:"favicon,omitempty"`
PrimaryColor string `json:"primary_color,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).