FlareHost
class FlareHost<TAdapter extends HostRuntimeAdapter<IFlareApp, LoggerTransportClass, HostRuntimeLifecycle, {}>, E extends readonly HostExtension<Record<never, never>>[] = readonly []>Composition root of a Flare application. new FlareHost(adapter) returns the host plus any members
the adapter stamps via extendHost.
How you get one
Section titled “How you get one”new FlareHost(adapter, extensions?)
Constructor
Section titled “Constructor”new FlareHost(adapter: TAdapter, extensions?: E): FlareHostadapter TAdapter
extensions? E
Properties
Section titled “Properties”http: HttpArc<AdapterLifecycle<TAdapter>>logging
Section titled “logging”logging: Logging<AdapterTransportClass<TAdapter>>ws: WebSocketArcWebSocket authoring surface: host.ws.route(path, opts?) and host.ws.controller(path, Class).
Accessors
Section titled “Accessors”config
Section titled “config”get config(): Readonly<FlareConfig>Resolved configuration produced from HostRuntimeAdapter.flareJsonFile, environment
variables, and registered descriptor defaults.
returns Readonly<FlareConfig>
logger
Section titled “logger”get logger(): LoggerFramework logger, bootstrapped during build before any user-land service is instantiated.
returns Logger
Throws:
If accessed before build has compiled the logger.
runtime
Section titled “runtime”get runtime(): HostRuntimeRuntime this host’s adapter targets.
returns HostRuntime
scopedServices
Section titled “scopedServices”get scopedServices(): ScopedServicesViewRead-only view of the per-request service registry compiled from scoped registrations.
returns ScopedServicesView
singletonServices
Section titled “singletonServices”get singletonServices(): ReadonlyMap<ServiceToken<FlareService>, FlareService>Read-only view of the singleton service instances compiled from singleton registrations.
returns ReadonlyMap<ServiceToken<FlareService>, FlareService>
get state(): HostStateCurrent lifecycle state of the host. Use in health-check / readiness routes instead of probing framework internals.
returns HostState
Example:
host.http.get("/ready", () => { return host.state === "ready" ? new FlareResponse(200, { state: host.state }) : new FlareResponse(503, { state: host.state });});Methods
Section titled “Methods”build()
Section titled “build()”build(): FlareApp<TAdapter>Compiles config, logger, validators, and DI registrations, then returns the runtime-specific
app produced by HostRuntimeAdapter.createApp. Idempotent: a second call returns the
cached app.
returns FlareApp<TAdapter>
Throws:
If any composite validator reports an error.
TODO(public-app-interface): Export a minimal public app interface (run/export/test entrypoints)
so consumers can annotate host.build() without relying on inferred internal app classes.
cfg(...tokens: ConfigToken<unknown>[]): thisRegisters one or more config tokens with the host.
Every token declared in a class’s static config array must be registered here, or
build will throw. Pre-defined framework tokens (HOST_CONFIG,
LOG_CONFIG) are registered automatically.
...tokens ConfigToken<unknown>[]
returns this
scoped()
Section titled “scoped()”scoped<T extends FlareService>(service: ServiceClass<T>): voidRegisters a per-request (scoped) service in the DI container.
The service is instantiated fresh for each request and disposed after the request
completes. Use singleton for long-lived services.
service ServiceClass<T> · The service class to register.
Throws:
If the class is missing the required static deps array.
whenState()
Section titled “whenState()”whenState(state: HostState): Promise<void>Resolves when the host reaches (or has already passed) the given lifecycle state.
States advance one way (starting -> ready -> draining -> stopped), so a waiter for a state
the host is already past resolves immediately. Useful for graceful-shutdown coordination, e.g.
deregistering from a load balancer the moment draining begins. On a runtime whose lifecycle
never leaves "ready" (Cloudflare Workers), a "draining"/"stopped" waiter never resolves.
state HostState
returns Promise<void>
Example:
void host.whenState("draining").then(() => registry.deregister(instanceId));Learn: Host