Skip to content
Strata is pre-1.0. APIs, protocol, and storage format may change.

strata_server

strata_server — top-level bootstrap.

Starts a supervised beryl channel system with the strata wire codec, registers the doc:* and admin:status channel handlers, opens the document store, and serves the WebSocket endpoint via mist (beryl_mist).

Authentication: clients must include a ?token=<value> query parameter on the WebSocket upgrade request. The token is compared to the value of the STRATA_TOKEN environment variable. Connections without a matching token are rejected with HTTP 403 before any socket process is spawned.

Origins: strata authenticates with an explicit token rather than ambient browser credentials, so by default every Origin is accepted. Set STRATA_ALLOWED_ORIGINS (comma-separated, e.g. https://app.example.com) to restrict upgrades to an allow-list.

A running server and its stable supervised handles.

pub type Server

Shutdown stops new work before attempting a final store close.

pub type ShutdownError {
DependentStopFailed(dynamic.Dynamic)
StoreCloseFailed(shelf.ShelfError)
ShutdownTimedOut
}

Server startup failures.

pub type StartError {
StorageDirectoryFailed(simplifile.FileError)
ChannelsFailed(channel.ChildSpecError)
SupervisorFailed(actor.StartError)
}

Server bootstrap configuration.

pub type StrataConfig {
StrataConfig(token: String, port: Int, websocket_path: String, storage_dir: String, static_dir: option.Option(String), admin_dir: option.Option(String), admin_status_interval_ms: Int, rate_limit_messages_per_second: Int, rate_limit_messages_burst: Int, rate_limit_joins_per_second: Int, rate_limit_joins_burst: Int, max_document_bytes: Int, allowed_origins: List(String))
}

Default interval for admin status broadcasts.

pub const default_admin_status_interval_ms: Int

Default HTTP port.

pub const default_port: Int

Default join burst capacity.

pub const default_rate_limit_joins_burst: Int

Default maximum joins per socket per second.

pub const default_rate_limit_joins_per_second: Int

Default burst capacity for message rate limit.

pub const default_rate_limit_messages_burst: Int

Default max messages per second.

pub const default_rate_limit_messages_per_second: Int

Default storage directory for DETS files.

pub const default_storage_dir: String

Default WebSocket path. Override via StrataConfig for non-default deployments.

pub const default_websocket_path: String

Build the wire codec and per-socket rate limits used by the server.

pub fn channel_config(StrataConfig) -> beryl.Config

Build a default config; reads STRATA_TOKEN and STRATA_DATA_DIR from the environment. Falls back to dev-only defaults if either is unset.

pub fn default_config() -> StrataConfig

Access the server's stable store handle for embedded applications.

pub fn document_store(Server) -> store.Store

Default main for gleam run in dev.

pub fn main() -> Nil

Split a comma-separated origin list, dropping blanks.

pub fn parse_origins(String) -> List(String)

Start the server and wait for its supervision tree to stop.

pub fn run(StrataConfig) -> Nil

Stop the listener and dependents, then close the store. On storage failure, service remains stopped and the store stays available for a shutdown retry. This API does not install an operating-system signal handler.

pub fn shutdown(Server) -> Result(Nil, ShutdownError)

Start the complete dependency tree. Abnormal store failure restarts the tracker, presence, sockets, admin collector, and listener in that order. The restart limit is two restarts in five seconds.

pub fn start(StrataConfig) -> Result(Server, StartError)