//! Run with //! //! ```not_rust //! cd examples && cargo run -p example-global-404-handler //! ``` use axum::{ http::StatusCode, response::{Html, IntoResponse}, routing::get, Router, }; use std::net::SocketAddr; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() { tracing_subscriber::registry() .with(tracing_subscriber::EnvFilter::new( std::env::var("RUST_LOG").unwrap_or_else(|_| "example_global_404_handler=debug".into()), )) .with(tracing_subscriber::fmt::layer()) .init(); // build our application with a route let app = Router::new().route("/", get(handler)); // add a fallback service for handling routes to unknown paths let app = app.fallback(handler_404); // run it let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); tracing::debug!("listening on {}", addr); axum::Server::bind(&addr) .serve(app.into_make_service()) .await .unwrap(); } async fn handler() -> Html<&'static str> { Html("