zagens_runtime_api/router.rs
1//! Router composition — public routes and CORS (D16 E1-c phase 2).
2//!
3//! Bearer auth on `/v1/*` is applied by the sidecar before calling [`compose_router`]
4//! so Axum state types stay aligned when merging route trees.
5
6use axum::Router;
7use axum::routing::get;
8
9use crate::cors::cors_layer;
10use crate::health::{health, internal_probe};
11use crate::state::RuntimeApiHostState;
12
13/// Mount `/health`, `/internal/probe`, merge authenticated `/v1/*`, and CORS defaults.
14///
15/// `api_routes` must already include the bearer-token [`route_layer`](axum::Router::route_layer)
16/// from the host crate.
17pub fn compose_router<S>(state: S, cors_origins: &[String], api_routes: Router<S>) -> Router
18where
19 S: RuntimeApiHostState,
20{
21 Router::new()
22 .route("/health", get(health))
23 .route("/internal/probe", get(internal_probe::<S>))
24 .merge(api_routes)
25 .layer(cors_layer(cors_origins))
26 .with_state(state)
27}