appserve

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package appserve is anfra serve's Data App component, its backend: the pages a browser opens (/apps/<path>, the appserve frontend), the Data Apps under the repo's apps/ (their tree, and the files themselves), who reads them, and live reload. It reaches no data: a Data App's queries go to the core API, from the browser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	Repo         RepoInfo  `json:"repo"`
	Reader       Reader    `json:"reader"`
	Watch        bool      `json:"watch"`
	AllowOrigins []string  `json:"allowOrigins"`
	Problems     []Problem `json:"problems"`
}

Context is what the frontend starts from: the repo, who reads it, whether it live-reloads, the origins its Data Apps may load from beyond the SDK's own (.anfra/config.yml apps.allow_origins), and the problems reading those settings, which the frontend shows with the repo's others.

type Entry

type Entry struct {
	Kind     string  `json:"kind"`
	Path     string  `json:"path"`
	Label    string  `json:"label,omitempty"`
	Name     string  `json:"name,omitempty"`
	Children []Entry `json:"children,omitempty"`
}

Entry is one node of the Data App tree: a Data App definition, or a folder of them.

func Catalog

func Catalog(repoDir string) []Entry

Catalog is every Data App definition under the repo's apps/, as a tree. Paths are relative to apps/, with their .html.

type Event

type Event struct {
	Type  string   `json:"type" enum:"apps,aml"`
	Paths []string `json:"paths,omitempty"`
}

Event is what a live-reloading frontend hears: Data App definitions (or files next to them) changed, by their paths under apps/; or the AML changed, so datasets and problems may have.

type Options

type Options struct {
	// RepoDir is the repo whose Data Apps are served, under its apps/.
	RepoDir string
	// Watch turns live reload on: while a Data App is open, a change in the repo is an event.
	Watch  bool
	Logger *slog.Logger
	// DevFrontendURL, when set, is a Vite dev server serving the frontend from source (make dev):
	// the pages redirect there, and it proxies the rest back. The built-in frontend, rebuilt only
	// by `pnpm build:web`, would be stale.
	DevFrontendURL string
}

Options configure a Server.

type Permissions

type Permissions struct {
	CanViewGeneratedSQL bool `json:"canViewGeneratedSql"`
	CanExportData       bool `json:"canExportData"`
}

type Problem added in v0.12.0

type Problem struct {
	Message string `json:"message"`
}

Problem is one problem with the repo's settings, as the frontend's problems banner shows it.

type Reader

type Reader struct {
	ID          int         `json:"id"`
	Name        string      `json:"name"`
	Email       string      `json:"email"`
	Role        string      `json:"role"`
	Timezone    string      `json:"timezone"`
	Permissions Permissions `json:"permissions"`
}

Reader is who reads the Data Apps, as the Anfra SDK provisions a user: on anfra serve, the local user, who may see everything.

func LocalReader

func LocalReader() Reader

LocalReader is the local user, with the machine's time zone.

type RepoInfo

type RepoInfo struct {
	Name string `json:"name"`
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server serves a repo's Data Apps. Mount it for /, /apps/ and /appserve/.

func New

func New(opts Options) *Server

New is a Server for opts, with the frontend built into this binary.

func (*Server) Close

func (s *Server) Close()

Close ends every event stream, so a server can shut down without waiting on them.

func (*Server) FrontendBuilt

func (s *Server) FrontendBuilt() bool

FrontendBuilt reports whether the pages have a frontend, built into this binary or a dev server: without one, the pages say how to build it, and the backend's routes still work.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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