Skip to main content

Module server

Module server 

Source
Expand description

§modo::server

HTTP server startup, host-based routing, and graceful shutdown.

Provides:

  • Config — bind address and shutdown timeout, deserialized from the server YAML section.
  • http() — binds a TCP listener, spawns the server on a background task, and returns an HttpServer handle.
  • HttpServer — opaque server handle that implements crate::runtime::Task so it composes with the crate::run! macro for coordinated graceful shutdown.
  • HostRouter — routes requests to different axum routers by Host header; supports exact matches and single-level wildcard subdomains with an optional fallback. Implements Into<axum::Router> so it plugs directly into http().
  • MatchedHost — axum extractor that exposes the subdomain captured by a wildcard HostRouter pattern (plus the pattern itself).

Trailing slashes are stripped from request paths before routing, so /app and /app/ resolve to the same handler (the root / is preserved).

§Quick start

use modo::{Config, Result};
use modo::axum::Router;

#[tokio::main]
async fn main() -> Result<()> {
    let config: Config = modo::config::load("config/")?;
    let app = Router::new();
    let server = modo::server::http(app, &config.server).await?;
    modo::run!(server).await
}

Structs§

Config
HTTP server configuration.
HostRouter
Routes requests to different axum Routers based on the Host header.
HttpServer
An opaque handle to the running HTTP server.
MatchedHost
Information about a wildcard host match.

Functions§

http
Bind a TCP listener and start serving router.