renderx

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMemPages = 1024
	DefaultTTL      = time.Hour
)
View Source
const (
	DefaultMemoryLimit = 512 << 20

	DefaultRenderTimeout = 3 * time.Second
)
View Source
const (
	DefaultCacheControl = "max-age=60, stale-while-revalidate=300"

	DefaultPoisonTTL = 10 * time.Minute
)
View Source
const DefaultIndexNowEndpoint = "https://api.indexnow.org/indexnow"
View Source
const DefaultPrelude = `` /* 5289-byte string literal not displayed */
View Source
const MaxPropsBytes = 512 << 10
View Source
const OutputVersion = "rv1"

Variables

View Source
var (
	ErrRenderTimeout = errors.New("renderx: render timeout")

	ErrPoolClosed = errors.New("renderx: engine pool closed")
)
View Source
var (
	ErrEmptyRenderOutput = errors.New("renderx: empty render output")

	ErrMissingTitle = errors.New("renderx: head directives emitted but no <title>")
)
View Source
var (
	ErrPatternNotFound = errors.New("renderx: pattern not registered")

	ErrPatternMismatch = errors.New("renderx: registered pattern not in route table")

	ErrMissingPaths = errors.New("renderx: static param route missing Paths")

	ErrInvalidParam = errors.New("renderx: invalid path param")

	ErrInvalidDirective = errors.New("renderx: invalid directive payload")

	ErrInvalidHeadTag = errors.New("renderx: invalid head tag or attr name")

	ErrInvalidCacheKey = errors.New("renderx: invalid cache key")

	ErrBuildIDMismatch = errors.New("renderx: cache entry buildId mismatch")

	ErrPropsTooLarge = errors.New("renderx: props exceed size limit")

	ErrPageNotFound = errors.New("renderx: page not found")
)

Functions

func AffectedPatterns

func AffectedPatterns(pattern string) []string

func BuildSSRBundle

func BuildSSRBundle(opts BuildOptions) ([]byte, error)

func DefaultPoolSize

func DefaultPoolSize() int

func DefaultSSRAliases

func DefaultSSRAliases(webDir, packagesDir string) map[string]string

func ExpandPath

func ExpandPath(pattern string, params Params) (string, bool)

func Handler

func Handler(deps HandlerDeps) http.Handler

func IndexNow

func IndexNow(ctx context.Context, deps IndexNowDeps, urls []string) error

func Invalidate

func Invalidate(ctx context.Context, pattern string, params Params) error

func PropsSHA256

func PropsSHA256(propsJSON []byte) string

func Reconcile

func Reconcile(routes []RouteSpec) error

func ReconcileEngine

func ReconcileEngine(ctx context.Context, r Renderer) error

func Refresh

func Refresh(ctx context.Context, pattern string, params Params) error

func RegisterDep

func RegisterDep(pagePattern, dependsOnPattern string)

func RegisterLoader

func RegisterLoader(pattern string, fn LoaderFn)

func RegisterPaths

func RegisterPaths(pattern string, fn PathsFn)

func RegisterService

func RegisterService(s *Service)

func RenderDocument

func RenderDocument(doc Document) ([]byte, error)

func ResetForTest

func ResetForTest()

func SitemapHandler

func SitemapHandler(routes []RouteSpec, baseURL string, opts SitemapOptions) http.Handler

func ValidParamValue

func ValidParamValue(v string) bool

func ValidateParams

func ValidateParams(p Params) error

func ViteBuildID

func ViteBuildID(data []byte) string

Types

type BuildOptions

type BuildOptions struct {
	EntryPoints []string

	AbsWorkingDir string

	NodePaths []string

	Alias map[string]string
}

type CacheConfig

type CacheConfig struct {
	BuildID  string
	MemPages int
	TTL      time.Duration
	Disk     *storagex.LocalBackend
}

type CacheEntry

type CacheEntry struct {
	HTML        []byte    `json:"html"`
	PropsSHA256 string    `json:"props_sha256"`
	BuiltAt     time.Time `json:"built_at"`
	BuildID     string    `json:"build_id"`
}

type DevHandler

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

func NewDevHandler

func NewDevHandler(deps DevHandlerDeps) (*DevHandler, error)

func (*DevHandler) Close

func (d *DevHandler) Close()

func (*DevHandler) ServeHTTP

func (d *DevHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type DevHandlerDeps

type DevHandlerDeps struct {
	BuildOpts BuildOptions

	PoolOpts PoolOptions

	NewRenderer func(bundle []byte, opts PoolOptions) (Renderer, error)

	Cache *LayeredCache

	Routes []RouteSpec

	BuildID string

	Assets ViteAssets
	Lang   string

	SPA http.Handler

	Registry *Registry

	Interval time.Duration

	Warn func(format string, args ...any)
}

type Directive

type Directive struct {
	Kind    string          `json:"kind"`
	Payload json.RawMessage `json:"payload,omitempty"`
	Seq     int             `json:"seq"`
}

type DirectiveSink

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

func NewSink

func NewSink() *DirectiveSink

func (*DirectiveSink) Append

func (s *DirectiveSink) Append(kind string, payload json.RawMessage) Directive

func (*DirectiveSink) Directives

func (s *DirectiveSink) Directives() []Directive

func (*DirectiveSink) Truncated

func (s *DirectiveSink) Truncated() bool

type Document

type Document struct {
	Lang          string
	Head          []HeadEntry
	CSS           []string
	BodyHTML      string
	PropsJSON     []byte
	PageID        string
	HydrateScript string
}

type EnginePool

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

func NewEnginePool

func NewEnginePool(bundle []byte, opts PoolOptions) (*EnginePool, error)

func (*EnginePool) Close

func (p *EnginePool) Close()

func (*EnginePool) Render

func (p *EnginePool) Render(ctx context.Context, pageID, location string, props json.RawMessage) (RenderResult, error)

func (*EnginePool) Routes

func (p *EnginePool) Routes(ctx context.Context) ([]RouteSpec, error)

type HandlerDeps

type HandlerDeps struct {
	PrerenderFS fs.FS

	SPA http.Handler

	Cache *LayeredCache

	Renderer Renderer

	Routes []RouteSpec

	BuildID string

	CacheControl string

	ErrorPage func(http.ResponseWriter, *http.Request, error)

	Warn func(format string, args ...any)

	Assets ViteAssets

	Lang string

	Registry *Registry

	PoisonTTL time.Duration
}

type HeadEntry

type HeadEntry struct {
	Tag      string            `json:"tag"`
	Attrs    map[string]string `json:"attrs,omitempty"`
	Children string            `json:"children,omitempty"`
}

func HeadEntries

func HeadEntries(dirs []Directive) ([]HeadEntry, error)

type IndexNowDeps

type IndexNowDeps struct {
	Endpoint string

	Key string

	Host string

	Client *http.Client
}

type LayeredCache

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

func NewLayeredCache

func NewLayeredCache(cfg CacheConfig) (*LayeredCache, error)

func (*LayeredCache) Delete

func (c *LayeredCache) Delete(ctx context.Context, paths ...string) error

func (*LayeredCache) EvictMatching

func (c *LayeredCache) EvictMatching(ctx context.Context, match func(key string) bool) (int, error)

func (*LayeredCache) Get

func (c *LayeredCache) Get(ctx context.Context, path string) (CacheEntry, bool)

func (*LayeredCache) GetOrLoad

func (c *LayeredCache) GetOrLoad(ctx context.Context, path string, load func(context.Context) (CacheEntry, error)) (CacheEntry, error)

func (*LayeredCache) GetStale

func (c *LayeredCache) GetStale(ctx context.Context, path string) (CacheEntry, bool)

func (*LayeredCache) Keys

func (c *LayeredCache) Keys() []string

func (*LayeredCache) PurgeForeign

func (c *LayeredCache) PurgeForeign(ctx context.Context, buildID string) error

func (*LayeredCache) Put

func (c *LayeredCache) Put(ctx context.Context, path string, ent CacheEntry) error

type LoaderFn

type LoaderFn func(ctx context.Context, p Params) (any, error)

type Mode

type Mode string
const (
	ModeStatic Mode = "static"

	ModeCSR Mode = "csr"
)

type PagePath

type PagePath struct {
	Params map[string]string `json:"params,omitempty"`
}

type Params

type Params map[string]string

func Match

func Match(pattern, path string) (Params, bool)

type PathsFn

type PathsFn func(ctx context.Context) ([]PagePath, error)

type PoolOptions

type PoolOptions struct {
	Size int

	MemoryLimit int

	RenderTimeout time.Duration

	Prelude string
}

type PrerenderDeps

type PrerenderDeps struct {
	Renderer Renderer

	OutDir string

	Routes []RouteSpec

	Warm []string

	BuildID string

	ViteAssets ViteAssets

	Lang string

	Concurrency int

	Registry *Registry
}

type PrerenderManifest

type PrerenderManifest struct {
	BuildID     string                   `json:"buildId"`
	GeneratedAt time.Time                `json:"generatedAt"`
	Pages       []PrerenderManifestEntry `json:"pages"`
}

func Prerender

func Prerender(ctx context.Context, deps PrerenderDeps) (PrerenderManifest, error)

type PrerenderManifestEntry

type PrerenderManifestEntry struct {
	Path        string    `json:"path"`
	PageID      string    `json:"pageId"`
	PropsSHA256 string    `json:"propsSha256"`
	BuildID     string    `json:"buildId"`
	BuiltAt     time.Time `json:"builtAt"`
	File        string    `json:"file"`
}

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func (*Registry) AffectedPatterns

func (r *Registry) AffectedPatterns(pattern string) []string

func (*Registry) LookupLoader

func (r *Registry) LookupLoader(pattern string) (LoaderFn, error)

func (*Registry) LookupPaths

func (r *Registry) LookupPaths(pattern string) (PathsFn, error)

func (*Registry) Reconcile

func (r *Registry) Reconcile(routes []RouteSpec) error

func (*Registry) RegisterDep

func (r *Registry) RegisterDep(pagePattern, dependsOnPattern string)

func (*Registry) RegisterLoader

func (r *Registry) RegisterLoader(pattern string, fn LoaderFn)

func (*Registry) RegisterPaths

func (r *Registry) RegisterPaths(pattern string, fn PathsFn)

type RenderResult

type RenderResult struct {
	HTML string
	Sink *DirectiveSink
}

type Renderer

type Renderer interface {
	Routes(ctx context.Context) ([]RouteSpec, error)

	Render(ctx context.Context, pageID, location string, props json.RawMessage) (RenderResult, error)
}

type RouteSpec

type RouteSpec struct {
	Path   string `json:"path"`
	PageID string `json:"pageId"`
	Render Mode   `json:"render"`
}

type Service

type Service struct {
	Cache    *LayeredCache
	Renderer Renderer
	Routes   []RouteSpec
	BuildID  string
	Assets   ViteAssets
	Lang     string
	Registry *Registry

	Warn func(format string, args ...any)

	RefreshTimeout time.Duration
}

func (*Service) Invalidate

func (s *Service) Invalidate(ctx context.Context, pattern string, params Params) error

func (*Service) Refresh

func (s *Service) Refresh(ctx context.Context, pattern string, params Params) error

type SitemapOptions

type SitemapOptions struct {
	Filter func(route RouteSpec, location string, params Params) bool

	Registry *Registry
}

type ViteAssets

type ViteAssets struct {
	CSS []string
	JS  []string
}

func ParseViteManifest

func ParseViteManifest(data []byte, entryKey string) (ViteAssets, error)

Directories

Path Synopsis
internal
qjs

Jump to

Keyboard shortcuts

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