pub async fn http(
router: impl Into<Router>,
config: &Config,
) -> Result<HttpServer>Expand description
Bind a TCP listener and start serving router.
Returns an HttpServer handle immediately; the server runs on a
background Tokio task. Pass the handle to crate::run! so it is
shut down gracefully when a signal arrives.
§Errors
Returns crate::Error if the TCP port cannot be bound.
§Example
use modo::server::{Config, http};
#[tokio::main]
async fn main() -> modo::Result<()> {
let config = Config::default();
let router = modo::axum::Router::new();
let server = http(router, &config).await?;
modo::run!(server).await
}With a HostRouter:
use modo::server::{self, Config, HostRouter};
#[tokio::main]
async fn main() -> modo::Result<()> {
let config = Config::default();
let app = HostRouter::new()
.host("acme.com", modo::axum::Router::new())
.host("*.acme.com", modo::axum::Router::new());
let server = server::http(app, &config).await?;
modo::run!(server).await
}