Macro static_dir::static_dir[][src]

macro_rules! static_dir {
    ($path:literal) => { ... };
}

Creates a Filter that serves a directory at the base $path joined by the request path.

It behaves much like warp’s fs::dir, but instead of serving files from the filesystem at runtime, the directory to be served will be embedded into your binary at compile time.

If the provided path is relative, it will be relative to the project root (as per the CARGO_MANIFEST_DIR environment variable).

Examples

use static_dir::static_dir;
use warp::Filter;

// Matches requests that start with `/static`, and then uses the
// rest of that path to lookup and serve a file from `/www/static`.
let route = warp::path("static").and(static_dir!("/www/static"));

// For example:
// - `GET /static/app.js` would serve the file `/www/static/app.js`
// - `GET /static/css/app.css` would serve the file `/www/static/css/app.css`