This commit is contained in:
2023-08-29 21:34:01 +02:00
parent 3719dfcef6
commit b80cae1278
11 changed files with 431 additions and 237 deletions

View File

@@ -1,10 +1,15 @@
use axum::{
error_handling::HandleErrorLayer,
http::header::HeaderMap,
http::StatusCode,
middleware,
routing::{get, post},
Router,
BoxError, Router,
};
use std::time::Duration;
use tower::{timeout::TimeoutLayer, ServiceBuilder};
use crate::{AppState, Error, RequestError, TopLevelPage};
use super::auth;
@@ -39,6 +44,13 @@ pub fn router(state: AppState) -> Router {
})
}),
)
.route(
"/slow",
get(|| async {
tokio::time::sleep(Duration::from_secs(1)).await;
"Ok"
}),
)
.route("/debug", get(debug))
.merge(
// thse are routes that require authentication
@@ -119,6 +131,15 @@ pub fn router(state: AppState) -> Router {
auth::authorize,
)),
)
.layer(
ServiceBuilder::new()
.layer(HandleErrorLayer::new(|_: BoxError| async {
tracing::warn!("request timeout");
StatusCode::REQUEST_TIMEOUT
}))
.layer(TimeoutLayer::new(Duration::from_millis(500))),
)
// .propagate_x_request_id()
.fallback(|| async {
Error::Request(RequestError::NotFound {
message: "no route found".to_string(),