ui

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package ui provides an embedded SPA file server for the Sparrow web frontend.

The static build output from web/build/ is embedded at compile time. When SPARROW_SERVE_UI=true, the Go binary serves the frontend on the same port as the Connect-RPC API. Chi router ensures API routes always take precedence; the UI handler is registered as the NotFound fallback.

Build the frontend first:

cd web && npm run build:static
cd .. && go build ./cmd/server

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Available

func Available() bool

Available reports whether the embedded UI contains a built frontend. Returns false if only the placeholder .gitkeep exists.

func Handler

func Handler(logger *slog.Logger, config *Config) http.Handler

Handler returns an http.Handler that serves the embedded SPA. It serves static files from the embedded filesystem, and falls back to index.html for any path that doesn't match a static file (SPA client-side routing).

The config parameter is injected into index.html as a window.__SPARROW_CONFIG__ global so the SPA can read runtime configuration without a rebuild.

Types

type Config

type Config struct {
	// APIKey is injected so the frontend can authenticate API requests.
	// Empty string means no authentication.
	APIKey string `json:"apiKey,omitempty"`
}

Config holds runtime configuration injected into the SPA HTML.

Jump to

Keyboard shortcuts

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