host

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 24 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 host wires the workflow-plugin-cms components into a single http.Handler suitable for a standalone CMS host binary.

The CMS plugin still ships as an external gRPC plugin (cmd/), but for standalone host deployments the engine runs in-process — this package exposes the same component set without the gRPC boundary.

Per CMS host SPEC.md §I and T13/T14/T16/T28/T31/T32.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// PreviewSubdomainBase is the FQDN suffix for preview subdomains
	// (e.g. "preview.gocodealone.com"). Empty disables preview-fallback
	// in the tenant resolver AND disables auto-provision of preview
	// domain rows on tenant create.
	PreviewSubdomainBase string

	// BundleRoot is the directory the static-serve middleware walks to
	// find <tenant>/current/<path>. Required.
	BundleRoot string

	// HMACSecret signs ingest webhooks (SPEC V8). Required for the
	// ingest endpoint to function; if empty, the endpoint returns 503.
	HMACSecret string

	// AdminHost, when set, moves the admin UI to https://<AdminHost>/
	// and requires all admin API/media/UI requests to use that host.
	// This avoids exposing admin under public tenant paths such as
	// /admin on the marketing site.
	AdminHost string

	// AdminAuth gates admin UI/API/media requests. Production should
	// wire this to workflow-plugin-auth session/JWT validation. When
	// AdminHost is set and AdminAuth is nil, admin requests fail closed.
	AdminAuth func(*http.Request) bool

	// AdminTenantAccess adds membership enforcement after role authorization.
	// Hosts with tenant editors must supply it; nil preserves legacy operator-only wiring.
	AdminTenantAccess func(*http.Request, int64) bool
	// AdminPlatformAccess is mandatory for tenant creation, domain reads/writes
	// and global cache reload. Hosts must enforce durable platform authority.
	AdminPlatformAccess func(*http.Request) bool

	// OnIngest is called with the verified payload. Production wires
	// this to a Fetcher; tests typically pass a no-op.
	OnIngest func(bundle.IngestPayload) error

	// Stores. Defaults are in-memory; production passes postgres-backed
	// implementations.
	TenantsAdmin store.TenantAdminStore
	Pages        store.PageStore

	// PageTemplates maps CMS template IDs to HTML shells containing
	// <!--cms:body-->. Missing/empty template IDs render the page body only.
	PageTemplates map[string]string

	// TenantResolverStore is the read-side tenant lookup interface used
	// by the resolver middleware. If both this and TenantsAdmin are
	// nil, a memory-backed store is created and shared between them
	// via a thin adapter.
	TenantResolverStore TenantResolverStore

	// AnalyticsConfigForTenant returns the per-tenant analytics config
	// (gtag measurement_id + anonymize_ip). Nil disables injection.
	AnalyticsConfigForTenant func(tenantID int64) analytics.TenantConfig

	// HealthCheck reports liveness (DB ping, etc.). Nil → always OK.
	HealthCheck func(ctx context.Context) error

	// MediaBackend persists tenant-scoped uploads. Nil disables the
	// upload endpoint (returns 503).
	MediaBackend media.Backend

	// AuditSignKey signs audit-chain entries. Empty disables audit
	// recording. Audit entries are emitted for tenant + page mutations.
	AuditSignKey string

	// AuditSink persists audit-chain entries. Nil uses an in-memory sink.
	// Ignored when AuditSignKey is empty.
	AuditSink audit.Sink

	// AuditActor returns the actor recorded for admin audit entries.
	// Empty return values fall back to "admin".
	AuditActor func(*http.Request) string
}

Config controls the host wiring.

type Server

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

Server is the assembled multisite host.

func New

func New(cfg Config) *Server

New builds a Server. Fills in memory-backed defaults for nil stores.

func (*Server) AdminAPI

func (s *Server) AdminAPI() *internal.AdminAPI

AdminAPI returns the underlying admin handler (for tests + advanced wiring).

func (*Server) Audit

func (s *Server) Audit() *audit.Logger

Audit returns the audit Logger if configured. May be nil.

func (*Server) EmitMetrics added in v0.1.3

func (s *Server) EmitMetrics(_ context.Context, recorder telemetry.MetricRecorder) error

func (*Server) ResolveTenant added in v0.1.6

func (s *Server) ResolveTenant(ctx context.Context, host string) (TenantInfo, bool)

ResolveTenant uses authoritative domain/tenant lookup. Host-policy decisions and public rendering share this lookup; an indefinitely cached mapping could serve the wrong tenant after a domain move. Resolver stores may optimize reads.

func (*Server) ServeHTTP

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

ServeHTTP routes a single request. Order of resolution:

  1. /healthz (always served, even without a Host header match)
  2. /api/v1/admin/* — handed to AdminAPI (+ media upload subroute)
  3. /api/v1/ingest/release — handed to IngestHandler (HMAC)
  4. Everything else → tenant resolve → static-serve → 404 if neither

Every request increments the per-tenant request counter (V30) keyed on the resolved tenant slug (or "_unresolved" for admin/system routes).

type TenantInfo

type TenantInfo = internal.TenantInfo

TenantInfo mirrors internal.TenantInfo so callers don't need to import internal.

type TenantResolverStore

type TenantResolverStore interface {
	Lookup(ctx context.Context, host string) (TenantInfo, bool)
	LookupBySlug(ctx context.Context, slug string) (TenantInfo, bool)
}

TenantResolverStore is the read-side tenant lookup interface — it is satisfied by `internal.TenantStore` (the resolver expects this shape).

Jump to

Keyboard shortcuts

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