clawdb_server/http/
mod.rs1pub mod auth;
2pub mod router;
3
4use std::sync::Arc;
5
6use anyhow::{Context, Result};
7use tokio::net::TcpListener;
8use tokio_util::sync::CancellationToken;
9
10use crate::{
11 http::router::{metrics_router, router},
12 state::AppState,
13};
14
15pub async fn serve(
16 listener: TcpListener,
17 state: Arc<AppState>,
18 shutdown: CancellationToken,
19) -> Result<()> {
20 axum::serve(listener, router(state))
21 .with_graceful_shutdown(async move {
22 shutdown.cancelled().await;
23 })
24 .await
25 .context("HTTP server failed")
26}
27
28pub async fn serve_metrics(
29 listener: TcpListener,
30 state: Arc<AppState>,
31 shutdown: CancellationToken,
32) -> Result<()> {
33 axum::serve(listener, metrics_router(state))
34 .with_graceful_shutdown(async move {
35 shutdown.cancelled().await;
36 })
37 .await
38 .context("metrics server failed")
39}