P3: wire serve end to end, integration tests, unit file, README

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YShymaPrXmc3KYRUg2HMSs
This commit is contained in:
ariandClaude Sonnet 5.5 committed 2026-10-15 19:21:53 -04:00
1 parent 936efaf97e
commit acedb9522e
10 files changed
+637 -16

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
//! Router assembly and the serve loop (P3). `build_router` is used by both
//! `slinuxm serve` and the integration tests.
use anyhow::{Context, Result};
use axum::routing::get;
use axum::Router;
use tokio_util::sync::CancellationToken;
use tower_http::trace::TraceLayer;
use crate::state::AppState;
use crate::{api, auth, mcp};
/// `/healthz` public; `/api/v1/*` and `/mcp` behind the auth layer.
pub fn build_router(state: AppState) -> Router {
let protected = Router::new()
.nest("/api/v1", api::router(state.clone()))
.nest_service("/mcp", mcp::service(state.clone()))
.layer(auth::layer(state));
Router::new()
.route("/healthz", get(api::healthz))
.merge(protected)
.layer(TraceLayer::new_for_http())
}
/// Serve `app` on `listener` until `shutdown` is cancelled.
pub async fn serve_listener(
listener: tokio::net::TcpListener,
app: Router,
shutdown: CancellationToken,
) -> Result<()> {
let addr = listener.local_addr().context("local_addr")?;
tracing::info!(%addr, "listening");
axum::serve(listener, app)
.with_graceful_shutdown(async move { shutdown.cancelled().await })
.await
.context("server error")
}