Documentation
¶
Overview ¶
Package bifrost serves Vite-built React Server, Static, and Client pages through the standard Go net/http stack. Vite owns frontend builds and development; Bun executes streaming SSR; Go owns server behavior.
Index ¶
- Variables
- func Building() bool
- func NotFound(cause error) error
- func Redirect(url string, status int) error
- type App
- type AppPlugin
- type AppRegistry
- func (r *AppRegistry) AddRoutes(routes ...Route) error
- func (r *AppRegistry) AssetHeaders(hook AssetHeaderHook) error
- func (r *AppRegistry) HandleErrors(handler ErrorHandler) error
- func (r *AppRegistry) OnLoad(hook LoadHook) error
- func (r *AppRegistry) OnQueue(hook QueueHook) error
- func (r *AppRegistry) OnRender(hook RenderHook) error
- func (r *AppRegistry) OnResponse(hook ResponseHook) error
- func (r *AppRegistry) Use(middleware Middleware) error
- type AssetHeaderHook
- type Config
- type Diagnostics
- type Document
- type ErrorHandler
- type Generator
- type Limits
- type LoadEvent
- type LoadHook
- type Loader
- type Middleware
- type PageData
- type QueueEvent
- type QueueHook
- type RawProps
- type RenderEvent
- type RenderHook
- type ResponseEvent
- type ResponseHook
- type Route
- type RouteInfo
- type StaticPage
Constants ¶
This section is empty.
Variables ¶
var ErrRendererBusy = errors.New("bifrost: renderer is busy")
var Version = detectedVersion()
Version identifies the Bifrost build tool in generated manifests. Release binaries derive it from Go module build information. It remains mutable so a release pipeline can set it with -ldflags when needed.
Functions ¶
func Building ¶ added in v1.1.0
func Building() bool
Building reports whether the app is running under the Bifrost describe or static-generation protocol. Main should return immediately after New in this mode, before opening databases, listeners, or other services.
Types ¶
type App ¶ added in v0.1.4
type App struct {
// contains filtered or unexported fields
}
App is an immutable, validated application model. Runtime services are added to this type after model compilation succeeds.
func MustNew ¶ added in v1.1.0
MustNew is New with panic-on-error behavior for programs that treat invalid app declarations as programmer errors.
func New ¶
New validates declarations, runs plugin registration, and starts the production runtime. Build phases may omit Assets; normal applications may not.
func (*App) Close ¶ added in v1.1.0
Close drains renderer work until ctx ends, then stops child processes.
func (*App) Diagnostics ¶ added in v1.1.0
func (a *App) Diagnostics() Diagnostics
Diagnostics returns a snapshot suitable for a development route table.
func (*App) Handler ¶ added in v0.1.4
Handler returns a standalone Bifrost handler. A setup failure produces a deterministic 503 response rather than a partially configured route table.
func (*App) Ready ¶ added in v1.1.0
Ready checks whether every renderer process can accept work. Applications with only Static or Client routes are ready when their runtime is compiled.
type AppPlugin ¶ added in v1.1.0
type AppPlugin interface {
Name() string
Register(*AppRegistry) error
}
AppPlugin adds server routes, HTTP middleware, and runtime hooks during app construction. Frontend plugins belong in vite.config.ts.
type AppRegistry ¶ added in v1.1.0
type AppRegistry struct {
// contains filtered or unexported fields
}
AppRegistry contains typed server extension points. An AppRegistry is valid only during AppPlugin.Register.
func (*AppRegistry) AddRoutes ¶ added in v1.1.0
func (r *AppRegistry) AddRoutes(routes ...Route) error
AddRoutes adds normal Bifrost routes. They receive the same validation as routes declared in Config.
func (*AppRegistry) AssetHeaders ¶ added in v1.1.0
func (r *AppRegistry) AssetHeaders(hook AssetHeaderHook) error
AssetHeaders installs an asset response header hook. The bool argument is true for a public/ file and false for a hashed build artifact.
func (*AppRegistry) HandleErrors ¶ added in v1.1.0
func (r *AppRegistry) HandleErrors(handler ErrorHandler) error
HandleErrors installs the app error handler. Only one plugin may install it.
func (*AppRegistry) OnLoad ¶ added in v1.1.0
func (r *AppRegistry) OnLoad(hook LoadHook) error
OnLoad registers a typed loader observation hook.
func (*AppRegistry) OnQueue ¶ added in v1.1.0
func (r *AppRegistry) OnQueue(hook QueueHook) error
OnQueue registers a typed renderer queue observation hook.
func (*AppRegistry) OnRender ¶ added in v1.1.0
func (r *AppRegistry) OnRender(hook RenderHook) error
OnRender registers a typed renderer observation hook.
func (*AppRegistry) OnResponse ¶ added in v1.1.0
func (r *AppRegistry) OnResponse(hook ResponseHook) error
OnResponse registers a typed response observation hook.
func (*AppRegistry) Use ¶ added in v1.1.0
func (r *AppRegistry) Use(middleware Middleware) error
Use appends standard HTTP middleware.
type AssetHeaderHook ¶ added in v1.1.0
AssetHeaderHook may add or replace headers for built and public assets.
type Config ¶ added in v1.1.0
type Config struct {
// SourceRoot is the directory against which frontend view paths resolve. An
// empty value means the current directory.
SourceRoot string
Routes []Route
AppPlugins []AppPlugin
// Assets contains a production manifest and its referenced files. When it
// is nil, New creates a declaration-only app for build and development
// phases.
Assets fs.FS
// RenderConcurrency is the number of isolated production renderer processes.
// Each process handles one render at a time. Zero uses one process. Development
// always uses one process because it owns one Vite module graph.
RenderConcurrency int
// RenderQueue bounds requests waiting for renderer capacity. Zero uses 64.
RenderQueue int
Limits Limits
Logger *slog.Logger
}
Config is the complete input to New. Its slices are copied during app construction.
type Diagnostics ¶ added in v1.1.0
Diagnostics describes the compiled app without exposing internal state.
type Document ¶ added in v1.1.0
Document describes request-scoped attributes on the root HTML element. Empty Lang defaults to "en". Dir may be empty, "ltr", "rtl", or "auto".
type ErrorHandler ¶ added in v1.1.0
type ErrorHandler func(http.ResponseWriter, *http.Request, error)
ErrorHandler handles an error before Bifrost writes a response.
type Generator ¶ added in v1.1.0
type Generator func(context.Context) ([]StaticPage, error)
Generator returns all documents emitted by a static route.
type Limits ¶ added in v1.1.0
Limits bounds buffered, attacker-influenced render data. The streamed total body size is not capped.
type LoadHook ¶ added in v1.1.0
LoadHook observes completed loader calls. It must not mutate request state.
type Middleware ¶ added in v1.1.0
Middleware is standard Go HTTP middleware.
type PageData ¶ added in v1.1.0
PageData lets a Server loader return props and root document attributes. A loader may still return plain props when it needs no document attributes.
type QueueEvent ¶ added in v1.1.0
QueueEvent reports one renderer admission and queue wait.
type QueueHook ¶ added in v1.1.0
type QueueHook func(context.Context, QueueEvent)
QueueHook observes renderer admission and queue outcomes.
type RawProps ¶ added in v1.1.0
type RawProps json.RawMessage
RawProps lets an advanced loader provide pre-encoded JSON. Bifrost validates, compacts, and safely escapes it before rendering.
type RenderEvent ¶ added in v1.1.0
RenderEvent reports one completed renderer call.
type RenderHook ¶ added in v1.1.0
type RenderHook func(context.Context, RenderEvent)
RenderHook observes completed renderer calls. It must not mutate render state.
type ResponseEvent ¶ added in v1.1.0
type ResponseEvent struct {
Pattern string
Status int
Bytes int64
Duration time.Duration
Err error
}
ResponseEvent reports one completed page response.
type ResponseHook ¶ added in v1.1.0
type ResponseHook func(context.Context, ResponseEvent)
ResponseHook observes completed page responses.
type Route ¶ added in v0.1.4
type Route struct {
// contains filtered or unexported fields
}
Route is an immutable page declaration. Use Server, Static, or Client to construct one.
type StaticPage ¶ added in v1.1.0
StaticPage describes one document emitted by a static route.