pub struct Server<S> { /* private fields */ }Expand description
The dashboard HTTP server, generic over whatever produces its state.
Build one with Server::new, optionally set the live-update cadence with
Server::with_push_interval, then block in Server::run (plain TCP) or
Server::run_on (a custom Transport).
§Examples
use pamoja_dashboard::{Assets, Server, State, StateSource, Status};
// Any StateSource works; a real node produces its live State here, and the
// `mock` feature's `Mock` is the hardware-free stand-in for development.
struct Node;
impl StateSource for Node {
fn snapshot(&mut self) -> State {
State { orgs: Vec::new(), status: Status::Ok, uptime_secs: None, demo: false }
}
}
let server = Server::new(Node, Assets::Embedded);
server.run("127.0.0.1:8080").expect("serve");Implementations§
Source§impl<S: StateSource + Send + 'static> Server<S>
impl<S: StateSource + Send + 'static> Server<S>
Sourcepub fn new(source: S, assets: Assets) -> Self
pub fn new(source: S, assets: Assets) -> Self
Creates a server that renders source with assets.
Control is authenticated against a freshly generated pairing secret that nobody
holds yet, so no client can issue commands until with_pairing_secret sets the
secret the device actually shows. Read-only viewing needs no pairing.
§Arguments
source- the state source to serve, a real node or aMock.assets- where the page files come from, embedded or a directory.
§Returns
A server pushing live updates once a second by default.
Sourcepub fn with_catalog(self, catalog: Catalog) -> Self
pub fn with_catalog(self, catalog: Catalog) -> Self
Serves a presentation Catalog at GET /catalog so the page can show the
deployment’s custom sensors, stats, and theme.
Build the catalog from the profiles the deployment runs with
Catalog::from_profiles. A catalog with nothing custom is not worth serving;
skip this call and the page keeps its built-in defaults.
§Arguments
catalog- the presentation catalog to serve.
§Returns
The server, for chaining.
Sourcepub fn with_pairing_secret(self, secret: impl Into<String>) -> Self
pub fn with_pairing_secret(self, secret: impl Into<String>) -> Self
Sourcepub fn with_push_interval(self, interval: Duration) -> Self
pub fn with_push_interval(self, interval: Duration) -> Self
Sourcepub fn run(self, addr: impl ToSocketAddrs) -> Result<()>
pub fn run(self, addr: impl ToSocketAddrs) -> Result<()>
Binds addr over plain TCP and serves forever.
§Arguments
addr- the address to listen on, such as"0.0.0.0:80".
§Returns
Never returns on success; it serves until the process ends.
§Errors
Returns the std::io::Error from binding the listener.
Sourcepub fn run_on<T: Transport>(self, transport: T) -> Result<()>
pub fn run_on<T: Transport>(self, transport: T) -> Result<()>
Serves forever over a supplied Transport, one thread per connection.
This is the seam for a non-default transport, such as a future TLS transport for a capable tier.
§Arguments
transport- the source of connections.
§Returns
Never returns on success; it serves until the process ends.
§Errors
Returns a std::io::Error only if accepting fails unrecoverably; transient
accept errors are skipped.