]> piware.de Git - learn-rust.git/commitdiff
axum-server: Serve whole directory
authorMartin Pitt <martin@piware.de>
Sat, 12 Nov 2022 10:18:04 +0000 (11:18 +0100)
committerMartin Pitt <martin@piware.de>
Sat, 12 Nov 2022 10:18:04 +0000 (11:18 +0100)
axum-server/src/main.rs

index 31c0a4f619576870762aebe5ab0ca3a7619b169c..02b4700d1e5352348e59d204b7e94f8332d64365 100644 (file)
@@ -47,8 +47,8 @@ async fn 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())
+        .nest("/static",
+               get_service(tower_http::services::ServeDir::new(".").precompressed_gzip())
                    .handle_error(|e: io::Error| async move {
                        (StatusCode::INTERNAL_SERVER_ERROR, format!("Unhandled internal error: {}", e))
                    })