+use std::io;
+
use axum::{
- routing::{get},
+ routing::{get, get_service},
extract::Path,
- http,
+ http::{StatusCode},
response,
Router};
async fn hello(Path(name): Path<String>) -> impl response::IntoResponse {
- (http::StatusCode::OK, format!("Hello {}", name))
+ (StatusCode::OK, format!("Hello {}", name))
}
#[tokio::main]
tracing_subscriber::fmt::init();
let app = Router::new()
.route("/hello/:name", get(hello))
+ .route("/static",
+ get_service(tower_http::services::ServeFile::new("Cargo.toml").precompressed_gzip())
+ .handle_error(|e: io::Error| async move {
+ (StatusCode::INTERNAL_SERVER_ERROR, format!("Unhandled internal error: {}", e))
+ })
+ )
.layer(
tower::ServiceBuilder::new()
.layer(tower_http::trace::TraceLayer::new_for_http())