tide-naive-static-files

A simple static file serving component for Rust's Tide web framework.

Acknowledgements

This code is based heavily on this archived example.

Example

To use the library:

  1. Define some state for your server.
  2. Implement StaticRootDir on your state. This tells the library how to access the name of the root directory in which your static assets live.
  3. Set up a get endpoint with a glob pattern (/my/path/for/static/assets/*) and have it call the serve_static_files function.

```rust use std::path::{Path, PathBuf}; use tidenaivestaticfiles::{servestatic_files, StaticRootDir};

struct AppState { // 1. staticrootdir: PathBuf, }

impl StaticRootDir for AppState { // 2. fn rootdir(&self) -> &Path { &self.staticroot_dir } }

[async_std::main]

async fn main() { let state = AppState { staticrootdir: "./examples/".into(), };

let mut app = tide::with_state(state);
app.at("/*") // 3.
    .get(|req| async { serve_static_files(req).await.unwrap() });
app.listen("127.0.0.1:8000").await.unwrap();

} ```

Problems

Right now it kinda doesn't use all the async-y-ness that it probably could. There are a couple of unfortunate task::block_ons that I want to get rid of. Suggestions welcome!