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"`
// AppLogs says whether the page sends its Data Apps' reports to anfra.log (POST /appserve/log).
AppLogs bool `json:"appLogs"`
}
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.
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
// AppLogger is where the Data Apps' reports from the browser go (POST /appserve/log): anfra.log,
// as "service":"app". Without one (ANFRA_NO_APP_LOGS), the page is told not to send them, and
// any sent anyway are taken and dropped.
AppLogger *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 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 Report ¶ added in v0.19.0
type Report struct {
// Path is the Data App's, under apps/.
Path string `json:"path"`
// Type is "error", "console" or "mounted" (no event: the page loaded the file as it is now).
Type string `json:"type"`
Event ReportEvent `json:"event"`
}
Report is what the appserve page posts to /appserve/log: one runtime error, or one console line, of the Data App at Path, as the SDK's host reported it (anfra.error, anfra.console), or that the page mounted it. It reaches anfra.log, so an agent reads a Data App's failures without a browser, and tells the ones from before an edit from the ones after it.
type ReportEvent ¶ added in v0.19.0
type ReportEvent struct {
Kind string `json:"kind,omitempty"`
Level string `json:"level,omitempty"`
Code string `json:"code,omitempty"`
Scope string `json:"scope,omitempty"`
Message string `json:"message"`
RequestID string `json:"requestId,omitempty"`
Entity string `json:"entity,omitempty"`
Call string `json:"call,omitempty"`
Stack string `json:"stack,omitempty"`
}
ReportEvent holds the fields of the SDK's AppErrorEvent and AppConsoleEvent that are logged. Rows and a request's params are never among them.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server serves a repo's Data Apps. Mount it for /, /apps/ and /appserve/.
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 ¶
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.