Skip to main content

synapse_proxy/
router.rs

1//! Router assembly shared by the binary and tests.
2use std::sync::atomic::AtomicBool;
3use std::sync::Arc;
4
5use axum::routing::get;
6use axum::Router;
7
8use crate::builder::ProxyBuilder;
9use crate::health;
10use crate::proxy::{self, AppState};
11
12pub fn build_router(state: AppState) -> Router {
13    Router::new()
14        .route("/healthz/liveness", get(health::liveness))
15        .route("/healthz/readiness", get(health::readiness))
16        .fallback(proxy::handler)
17        .with_state(state)
18}
19
20/// Build the data-plane router from a builder (used by integration tests).
21pub fn build_router_from_config(builder: ProxyBuilder) -> anyhow::Result<Router> {
22    let built = builder.build()?;
23    let (metrics, _registry) = crate::metrics::Metrics::new()?;
24    let state = AppState {
25        routes: Arc::new(built.routes),
26        context: built.context,
27        client: reqwest::Client::new(),
28        shutting_down: Arc::new(AtomicBool::new(false)),
29        metrics: Arc::new(metrics),
30    };
31    Ok(build_router(state))
32}