build_router

Function build_router 

Source
pub fn build_router(state: Arc<ServerState>) -> Router
Expand description

Build the axum router with all API endpoints and OpenAPI doc routes.

Structure:

  • /api/v1/* — the main resource router, with the global ServerState::request_timeout applied as an outer TimeoutLayer. POST /power now returns immediately with a PCS transition id (the polling loop runs CLI-side), so it fits well under the default timeout — no per-route override is needed. A second outer layer (read_only_guard) refuses mutating methods (POST/PUT/PATCH/DELETE) when the caller’s JWT carries the READ_ONLY_ROLE role.
  • /api/v1/auth/* — separate sub-router with two layered defences: per-IP rate limit (see AuthRateLimiter) and body redaction from any log span (see strip_body_for_logs). No Bearer-token extractor (these endpoints issue the token).
  • /docs + /openapi.json — Swagger UI and the spec from ApiDoc.
  • HSTS header injected on every response by an add_hsts_header middleware (private to this module).