Michael-F-Bryan / include_dir

The logical evolution of the include_str macro for embedding a directory tree into your binary.
https://michael-f-bryan.github.io/include_dir
MIT License
319 stars 36 forks source link

Feature request: tower compatible #79

Closed Folyd closed 2 years ago

Folyd commented 2 years ago

tower-http provides a handy ServeDir to serve directory HTTP requests. I think we can also make the Dir tower compatible?

Michael-F-Bryan commented 2 years ago

What does "make the Dir tower compatible" mean?

Folyd commented 2 years ago

What i mean is this:

// This will serve files in the "assets" directory and
// its subdirectories
- let service = ServeDir::new("assets");
+ let service: Dir<'_> = include_dir::include_dir!("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");
Michael-F-Bryan commented 2 years ago

You will need create your own tower-include-dir crate which exposes a tower::Service implementation backed by include_dir::Dir. This is outside the scope of the include_dir project.

Folyd commented 2 years ago

Ok, I see. It's possible to make this under the tower feature flag in this crate? If so, I can file a PR. ^^-

Michael-F-Bryan commented 2 years ago

It sounds like this is functionality you care about, so I would encourage you to publish your own tower-include-dir crate. I don't want to add it under a feature flag because that's extra maintenance work for me and it would tie include_dir's versioning to tower (e.g. when I publish include_dir v1.0, I'll need to make another major release when tower goes from 0.4 to 0.5).