A simple static file serving component for Rust's Tide web framework.
This code is based heavily on this archived example.
This crate is not officially associated with the tide
project, it's more of an interim solution while tide
is still in a state of (relative) flux.
Mistakes were made when initially selecting version numbers for this crate. In the Rust ecosystem, a 1.0.0 release generally means the crate is fit for production. This crate makes no such claim. It would be best to "divide by ten" when looking at the crate's version number (i.e. 2.0.1 should be thought of as 0.2.0.1).
To use the library:
- Define the route to host your assets under
- Stip the prefix so the routes match your files
- Set up a
get
endpoint with theStaticFilesEndpoint
making sure theroot
represents the path from where you run the server to the root of your assets
use async_std::task;
use tide_naive_static_files::StaticFilesEndpoint;
fn main() {
let mut app = tide::new();
app.at("/static") // 1.
.strip_prefix() // 2
.get(StaticFilesEndpoint {
root: "./examples/".into(), // 3.
});
task::block_on(app.listen("127.0.0.1:8000")).unwrap();
}
- eignnx
- Felipe Seré, felipesere
If you're interested in contributing to the project, please see our CONTRIBUTING.md file!