host

package
v0.0.0-...-9457e37 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package host wires the workflow-plugin-cms components into a single http.Handler suitable for a standalone multisite host binary.

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

Per gocodealone-multisite 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

	// 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

	// 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
}

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) 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
  3. /api/v1/ingest/release — handed to IngestHandler (HMAC)
  4. Everything else → tenant resolve → static-serve → 404 if neither

Cross-cutting: every response gets per-tenant analytics injection IF the response is HTML AND the tenant has a measurement_id.

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