Skip to main content

serve

Function serve 

Source
pub async fn serve(
    addr: &str,
    app: Router,
    server: &ServerConfig,
    config_dir: &Path,
    profile: &str,
) -> Result<()>
Expand description

启动 HTTP 服务

根据 server.ssl_enabled 选择 HTTP/1.1 或 HTTPS + HTTP/2 模式。

§参数

  • addr: 监听地址,格式 "host:port"
  • app: axum Router(含所有路由和中间件)
  • server: 服务端配置(SSL 开关和证书路径)
  • config_dir: 配置目录(用于解析相对路径证书)
  • profile: 当前运行 profile(“dev” / “dev-h2” / “pro”)

§Panics

不 panic。所有启动失败均通过 anyhow::Result 返回。

§优雅关闭

axum/axum-server 自动处理 SIGTERM 信号,不丢失正在处理的请求。