A [`Router`] that serves all of the REST API routes, and the `OpenAPI` specification.
(dependencies: RestRouterDependencies<S>)
| 430 | |
| 431 | /// A [`Router`] that serves all of the REST API routes, and the `OpenAPI` specification. |
| 432 | pub fn rest_api_router<S>(dependencies: RestRouterDependencies<S>) -> Router |
| 433 | where |
| 434 | S: StorePool + Send + Sync + 'static, |
| 435 | for<'p> S::Store<'p>: RestApiStore + PrincipalStore + PolicyStore, |
| 436 | { |
| 437 | // All api resources are merged together into a super-router. |
| 438 | let merged_routes = api_resources::<S>() |
| 439 | .into_iter() |
| 440 | .fold(Router::new(), Router::merge) |
| 441 | .fallback(|| { |
| 442 | tracing::error!("404: Not found"); |
| 443 | async { StatusCode::NOT_FOUND } |
| 444 | }); |
| 445 | |
| 446 | // super-router can then be used as any other router. |
| 447 | // Make sure extensions are added at the end so they are made available to merged routers. |
| 448 | // The `/api-doc` endpoints are nested as we don't want any layers or handlers for the api-doc. |
| 449 | // We use a `ServiceBuilder` to add the layers in the correct order. |
| 450 | let mut router = merged_routes |
| 451 | .layer( |
| 452 | ServiceBuilder::new() |
| 453 | .layer(NewSentryLayer::new_from_top()) |
| 454 | .layer(SentryHttpLayer::default().enable_transaction()), |
| 455 | ) |
| 456 | .layer(http_tracing_layer::HttpTracingLayer) |
| 457 | .layer(Extension(dependencies.store)) |
| 458 | .layer(Extension(dependencies.temporal_client)) |
| 459 | .layer(Extension(dependencies.domain_regex)) |
| 460 | .layer(Extension(dependencies.api_config)); |
| 461 | |
| 462 | if let Some(query_logger) = dependencies.query_logger { |
| 463 | router = router.layer(Extension(query_logger)); |
| 464 | } |
| 465 | |
| 466 | router.merge(openapi_only_router()) |
| 467 | } |
| 468 | |
| 469 | async fn serve_static_schema(Path(path): Path<String>) -> Result<Response, StatusCode> { |
| 470 | let path = path.trim_start_matches('/'); |
no test coverage detected