[][src]Function tide_naive_static_files::serve_static_files

pub async fn serve_static_files(ctx: Request<impl StaticRootDir>) -> Result

Use in a tide tide::Route::get handler to serve static files from an endpoint. In order to use this function, your tide app's state must implement the StaticRootDir trait.

The static assets will be served from the route provided to the app.at function. In the example below, the file ./my-static-asset-dir/foo.html would be obtainable by making a GET request to http://my.server.address/static/foo.html.

use std::path::Path;
use tide_naive_static_files::{StaticRootDir, serve_static_files};

struct MyState;

impl StaticRootDir for MyState {
    fn root_dir(&self) -> &Path {
        Path::new("./my-static-asset-dir")
    }
}

let state = MyState;
let mut app = tide::with_state(state);
app.at("static/*path")
    .get(|req| async { serve_static_files(req).await.unwrap() });