server

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Overview

Package server exposes the CMS core over a JSON HTTP API.

Index

Constants

View Source
const DefaultAssetCacheMaxAge = time.Hour

DefaultAssetCacheMaxAge is how long a client may keep a site asset when nothing else applies.

View Source
const DefaultContentSharedMaxAge = time.Minute

DefaultContentSharedMaxAge is how long a shared cache may serve a public read by default.

View Source
const DefaultContentStaleWhileRevalidate = 5 * time.Minute

DefaultContentStaleWhileRevalidate is how long a shared cache may serve a stale read by default.

View Source
const DefaultDefinitionsImportCap int64 = 256 << 10

DefaultDefinitionsImportCap is how large a definitions file an import takes when nothing else is named.

View Source
const DefaultMediaCacheMaxAge = time.Hour

DefaultMediaCacheMaxAge is how long a client may keep a served upload when nothing else applies.

View Source
const MaxDefinitionsImportCap int64 = authkit.MaxRequestBodyBytes

MaxDefinitionsImportCap is the largest definitions cap the request body reader can carry.

Variables

This section is empty.

Functions

func NewServer

func NewServer(cfg Config) http.Handler

NewServer returns the HTTP handler serving the CMS API. Every route requires a login session except login, logout, and each plugin's declared public paths.

Types

type CachePolicy added in v0.11.0

type CachePolicy struct {
	// AssetMaxAge is how long a client may keep a site asset.
	AssetMaxAge time.Duration
	// MediaMaxAge is how long a client may keep a served upload.
	MediaMaxAge time.Duration
	// ContentSharedMaxAge is how long a shared cache may serve a public read.
	ContentSharedMaxAge time.Duration
	// ContentStaleWhileRevalidate is how long a shared cache may serve a stale read.
	ContentStaleWhileRevalidate time.Duration
}

CachePolicy is how long each kind of public answer may be kept. Zero applies the default.

type Config

type Config struct {
	Users authkit.AdminStore
	// Content persists the content the CMS serves.
	Content content.Store
	// Types persists the content type registry. Nil leaves the registry routes unhandled.
	Types content.TypeStore
	// Registry is the content registry the server shares with the host, built over Types when nil.
	Registry *content.Registry
	// Plugins maps a plugin id to its HTTP handler.
	Plugins map[string]http.Handler
	// PluginPublicPaths maps a plugin id to its session-exempt paths.
	PluginPublicPaths map[string][]string
	// Web serves the single-page app under the admin base path. Nil leaves the admin paths unhandled.
	Web fs.FS
	// SiteTitle names the public site in its chrome.
	SiteTitle string
	// TrustedProxies lists the CIDR ranges trusted to set X-Forwarded-For.
	TrustedProxies []string
	// Theme serves the public site while it is healthy. Nil leaves the built-in renderer serving.
	Theme Theme
	// Themes is the managed themes directory. Nil leaves the theme routes unhandled.
	Themes Themes
	// Media is the media library uploads land in. Nil leaves the media routes unhandled.
	Media MediaLibrary
	// MediaStore persists the media library. Nil leaves the media routes unhandled.
	MediaStore media.Store
	// MediaFiles serves the stored uploads publicly. Nil leaves the media prefix reserved but empty.
	MediaFiles fs.FS
	// Cache is how long each kind of public answer may be kept. A zero window applies its default.
	Cache CachePolicy
	// ThemeTimeout is how long a theme has to begin answering. Zero applies the default.
	ThemeTimeout time.Duration
	// Version is the application version reported at /api/version.
	Version string
	// Settings persists the values the site chooses for itself. Nil leaves the site default unread.
	Settings SiteSettings
	// Readers persists the values one reader chooses. Nil leaves the locale preference unhandled.
	Readers ReaderSettings
	// DefinitionsImportCap is the largest definitions file an import takes. Zero applies its default.
	DefinitionsImportCap int64
	// Declarations is what every plugin declared at the last boot, by the plugin that declared it.
	Declarations definitions.Walked
}

Config carries the stores and plugin surfaces the server serves.

type MediaLibrary added in v0.3.0

type MediaLibrary interface {
	// Cap returns the most bytes one upload may carry.
	Cap() int64
	// Ingest validates an upload, stores its files, and returns the media item they make.
	Ingest(ctx context.Context, name string, data []byte, authorID uuid.UUID) (media.Media, error)
	// Remove deletes the item's stored file and every rendition it owns.
	Remove(m media.Media) error
}

MediaLibrary validates uploads and owns the media directory.

type ReaderSettings added in v0.6.0

type ReaderSettings interface {
	Lookup(ctx context.Context, userID uuid.UUID, key string) (string, bool, error)
	Save(ctx context.Context, userID uuid.UUID, key, value string) error
}

ReaderSettings persists the values one reader chooses for themselves.

type SiteSettings added in v0.6.0

type SiteSettings interface {
	Lookup(ctx context.Context, key string) (string, bool, error)
	Save(ctx context.Context, values map[string]string) error
}

SiteSettings persists the values a site chooses for itself.

type Theme

type Theme interface {
	// Healthy reports whether the theme is serving.
	Healthy() bool
	// Target returns the address the theme serves on.
	Target() string
}

Theme is the running theme the public site is served through.

type Themes added in v0.2.0

type Themes interface {
	// List returns the installed themes, marking the one that is active.
	List(ctx context.Context) ([]themehost.Installed, error)
	// Install unpacks the archive as the named theme.
	Install(ctx context.Context, name string, archive io.ReaderAt, size int64) error
	// Activate serves the public site through the named theme.
	Activate(ctx context.Context, name string) error
	// Deactivate returns the public site to the built-in renderer.
	Deactivate(ctx context.Context) error
	// Rollback returns the public site to the choice before the current one, naming it.
	Rollback(ctx context.Context) (string, error)
	// Previous returns the choice a rollback would return to, and whether one is offered.
	Previous(ctx context.Context) (string, bool, error)
}

Themes is the managed themes directory the admin lists and installs into.

Jump to

Keyboard shortcuts

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