server

package
v0.0.0-...-c0bf4df Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: BSD-3-Clause Imports: 35 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package server exposes stored presentations over HTTP as single-page views. It reads the store and core template fresh on every request, so both content updates and template edits are reflected immediately without a restart.

Index

Constants

View Source
const (
	// DefaultHeartbeat is how often an idle stream resends the version. It
	// stays under the 60 second idle timeout common in proxies, and it lets
	// the browser tell a live stream from one a buffering proxy holds back.
	DefaultHeartbeat = 25 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Mode

type Mode int

Mode selects what the server exposes.

const (
	// ModeLocal is present on one machine: an index of every page, listing
	// and delete without authentication, bound to loopback.
	ModeLocal Mode = iota
	// ModeShared is a network-facing instance: pages by id only, a how-to
	// page instead of an index, author keys on every write, and the MCP
	// server over HTTP at /mcp.
	ModeShared
)

type Options

type Options struct {
	Mode      Mode
	Workdir   string
	Info      buildinfo.Info
	BaseURL   string
	SpeakURL  string
	Now       func() time.Time
	MCP       http.Handler
	Sharer    *sharedclient.Client
	Watcher   PageWatcher
	Heartbeat time.Duration

	Terminals       *terminal.Manager
	TerminalSwitch  string
	TerminalOrigins []string
}

Options configures a Server. Workdir is where the served assets live; Info is present's own build metadata, reported on GET /version. BaseURL is the display override for the URLs shared writes return; empty means derive it from each request's forwarded headers. MCP, when set in shared mode, is mounted at /mcp. Sharer, in local mode, is the shared instance pages can be pushed to; nil hides the share button and its endpoint. Watcher, when set, mounts GET /p/{id}/events, which pushes a page's version to open tabs as it changes; without it tabs poll /p/{id}/version. Heartbeat is how often an idle event stream resends the version, DefaultHeartbeat when zero. SpeakURL is the speak service the page view registers a page's text with for read-aloud; empty leaves read-aloud out of the page. Terminals, in local mode, owns the live terminal sessions behind the switch file at TerminalSwitch; nil leaves the terminal routes out, and a shared instance never has them. TerminalOrigins adds browser origin patterns (path.Match against the Origin host) to the present.this and loopback origins a terminal socket accepts. Now defaults to time.Now.

type PageWatcher

type PageWatcher interface {
	// WatchPage returns a channel that receives after page id changes,
	// coalescing bursts, and a stop func that releases it.
	WatchPage(id string) (<-chan struct{}, func())
}

PageWatcher tells the server when a page may have changed, so it can push the page's version to open tabs instead of waiting for their next poll. The cluster store is one. The filesystem store is not: on one machine the MCP process writes the pages, and serve never hears of it.

type Server

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

Server serves the index and individual presentation pages.

func New

func New(st store.Store, opts Options) *Server

New returns a Server backed by the given store.

func (*Server) CloseStreams

func (s *Server) CloseStreams()

CloseStreams ends every open event stream and any opened after it. Serve calls it when shutdown starts: a stream never finishes on its own, so without this a graceful shutdown would wait out its whole drain timeout. It is safe to call more than once.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler builds the HTTP routes for the server's mode, wrapped in forwarded-header defaults and request logging. The page view, the deck view, their JSON, the version poll, delete, the section patch and progress routes, assets, and webkit are common. So is the version event stream whenever a watcher is configured, the deck command poll whenever the store relays commands, and the history and diff routes whenever the store keeps history (the raw filesystem store alone); local mode adds the index, its listing, the markdown import, the stored images, and the live terminal routes when a terminal manager is configured; shared mode the how-to root, the write API, whoami, and the MCP endpoint. A route the mode does not register is a plain 404.

func (*Server) SweepImages

func (s *Server) SweepImages(ctx context.Context)

SweepImages removes the stored images no page references, in a rendition or in a Doc source, and logs what it did. It runs once at startup and after every delete. A failure is logged rather than returned: nothing waits on a sweep, and the next one tries again. Files younger than a minute stay whatever references them, so an image the MCP process wrote for a page it is about to store is never taken from under it.

type Standalone

type Standalone struct {
	ShellCSS        string
	FixationTargets string
	VizJS           string
	AppJS           string
}

Standalone is what the page view needs from this package to run with no server behind it: the shell's own stylesheet, the fixation targets its header names, viz.js, and app.js. internal/export assembles them into one file, so an exported page keeps the look and behaviour of the served one.

func StandaloneAssets

func StandaloneAssets() (Standalone, error)

StandaloneAssets cuts the stylesheet and the fixation targets out of the embedded shell.html and returns them with viz.js and app.js. An error means the shell no longer carries the markup the cut looks for.

Jump to

Keyboard shortcuts

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