Static file serving

This commit is contained in:
David Pedersen
2021-06-06 21:53:22 +02:00
parent 91b1b0bc50
commit 58c18c2563
2 changed files with 48 additions and 0 deletions
+21
View File
@@ -514,6 +514,27 @@
//! # };
//! ```
//!
//! `nest` can also be used to serve static files from a directory:
//!
//! ```rust,no_run
//! use tower_web::{prelude::*, ServiceExt, routing::nest};
//! use tower_http::services::ServeDir;
//! use http::Response;
//! use std::convert::Infallible;
//! use tower::{service_fn, BoxError};
//!
//! let app = nest(
//! "/images",
//! ServeDir::new("public/images").handle_error(|error: std::io::Error| {
//! // ...
//! })
//! );
//! #
//! # async {
//! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await;
//! # };
//! ```
//!
//! [tower]: https://crates.io/crates/tower
//! [tower-http]: https://crates.io/crates/tower-http