start_server

Function start_server 

Source
pub async fn start_server(
    state: Arc<ServerState>,
    listen_addr: &str,
    port: u16,
    cert_path: Option<&str>,
    key_path: Option<&str>,
) -> Result<(), Error>
Expand description

Start the HTTP or HTTPS server.

Builds the router via routes::build_router, wraps it with the request-logging middleware, binds the listener at <listen_addr>:<port>, and serves until a SIGTERM or Ctrl+C is received — at which point the in-process shutdown handler triggers axum_server’s graceful drain with the ServerState::shutdown_grace_period window.

When cert_path and key_path are both Some, the server listens with TLS (https://). When both are None, it listens as plain HTTP. Mixing one of the two is rejected.

§Errors

  • [Error::BadRequest] when listen_addr:port does not parse as a SocketAddr, or when exactly one of cert_path / key_path is supplied (they must be set together).
  • Any I/O / TLS load error from RustlsConfig::from_pem_file or the underlying axum_server::bind* call surfaces via the From<io::Error> impl on [Error].