From b81eaf785286519b9e5b7725cc4d4dd66175a892 Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Thu, 9 Jun 2022 12:58:56 -0400 Subject: main: Add 404 handler --- src/main.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 742113e..28036d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use axum::{ http::StatusCode, response::IntoResponse, routing::{get, post}, + handler::Handler, Json, Router }; @@ -52,7 +53,8 @@ async fn main() { .timeout(Duration::from_secs(10)) .layer(TraceLayer::new_for_http()) .into_inner(), - ); + ) + .fallback(handler_404.into_service()); let addr = SocketAddr::from_str(std::env::var("BIND_ADDR").unwrap().as_str().into()).unwrap(); tracing::info!("Listening on {}", addr); @@ -72,3 +74,7 @@ fn get_star() -> Result { Ok(Star::new(con_url)?) } + +async fn handler_404() -> impl IntoResponse { + StatusCode::NOT_FOUND +} -- cgit v1.2.3