9 releases

0.1.9 Sep 1, 2023
0.1.8 Jan 20, 2023

#897 in Filesystem

39 downloads per month

MIT license

105KB
2.5K SLoC

http_dir

like tower_http::service::ServeDir, but allows user provide a Filesystem implement

this crate is fork from tower_http::service::ServeDir, thanks for tower_http crate

Notice

this crate require nightly features:

  • type_alias_impl_trait

License

This project is licensed under the MIT license.


lib.rs:

HTTP file server, to access files on the Filesystem. User can implement own Filesystem, also can use DiskFilesystem or IncludeDirFilesystem directly

Note

This crate require TAIT feature, it will be stable soon but now it is a nightly feature

Example

use http_dir::ServeDir;
use http_dir::fs::disk::DiskFilesystem;

// This will serve files in the "assets" directory and
// its subdirectories
let service = ServeDir::new(DiskFilesystem::from("assets"));

// Run our service using `hyper`
let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 3000));
hyper::Server::bind(&addr)
    .serve(tower::make::Shared::new(service))
    .await
    .expect("server error");

Dependencies

~5–11MB
~115K SLoC