macro_rules! asset_dir {
(@option $opt:expr) => { ... };
($dir:expr) => { ... };
}Expand description
Vial can serve static files out of an asset directory, complete with ETag support so your browser isn’t constantly re-downloading.
To enable this, put all your .js and .css and other static
assets into a directory in the root of your project, then
reference them as if the root of your Vial web application was
that asset directory. Next call vial::asset_dir!() with the path
to your asset directory (maybe assets/?) before starting your
application with vial::run!:
If we had a directory structure like this: . ├── README.md ├── assets │ └── img │ ├── banker.png │ └── doctor.png └── src └── main.rs
We could serve our images like so:
vial::routes! {
GET "/" => |_| "
<p><img src='/img/doctor.png'/></p>
<p><img src='/img/banker.png'/></p>
";
}
fn main() {
vial::asset_dir!("assets/");
vial::run!().unwrap();
}