pub struct Router { /* private fields */ }Expand description
Routes requests to the surfaces this process serves. Cheap to clone: every worker thread holds one, and the resolution behind it is shared.
Implementations§
Source§impl Router
impl Router
Sourcepub fn new(live: impl IntoLive, version: &'static str) -> Self
pub fn new(live: impl IntoLive, version: &'static str) -> Self
A router over a view of the repository, without /mcp and without the Cockpit.
live is either the Live the shared server follows the repository with or a
plain Arc<Context>, which becomes a pinned view: a one-shot process and a
benchmark have nothing to follow and pay nothing to prove it.
Sourcepub fn with_cockpit(self, share_dir: Option<&Path>) -> Self
pub fn with_cockpit(self, share_dir: Option<&Path>) -> Self
The same router, serving the Cockpit’s pages with its assets read from share_dir.
Sourcepub fn with_ui(self, share_dir: Option<&Path>) -> Self
pub fn with_ui(self, share_dir: Option<&Path>) -> Self
The same router, serving the UI’s pages (ADR 0135) with its assets read from
share_dir. Without a distribution the screens are still complete HTML, unstyled;
either way the UI becomes one of the surfaces the topology says this process serves.
let router = router.with_ui(None);
let served = router.served().expect("a topology that resolves");
assert!(served.topology().surfaces.iter().any(|s| s.id == majordomus_cli::ui::SURFACE));Sourcepub fn with_mcp(self, endpoint: Arc<McpEndpoint>) -> Self
pub fn with_mcp(self, endpoint: Arc<McpEndpoint>) -> Self
The same router, serving MCP over HTTP through endpoint.
Sourcepub fn served(&self) -> Result<ServedRef, Error>
pub fn served(&self) -> Result<ServedRef, Error>
The surfaces this router serves, for a caller that wants to describe them: the server’s startup line, and the tests.
The answer is the resolution, not a fresh discovery — a router that could not resolve its topology never answered a request either, and says the same thing here that it says to a client.
Sourcepub fn websocket(&self, req: &Request) -> Option<Result<Accepted, Response>>
pub fn websocket(&self, req: &Request) -> Option<Result<Accepted, Response>>
Does this request open the live channel, and may it?
The server asks before it reads a body or writes a response, because an upgrade is
the one thing a router cannot answer: it hands the socket over. None means the
request is not for the live channel at all and is routed normally.
Sourcepub fn handle(&self, req: &Request) -> Response
pub fn handle(&self, req: &Request) -> Response
Answer one request: the surface that owns its path, or nothing.
A request that carries an Origin header came from a page in a browser. A browser
cannot read a cross-origin response without the headers this server never sends,
so a read is already contained; a request that changes something is not, and one
from another origin is refused before it reaches a handler. A client that is not a
browser sends no Origin and is unaffected.