rocket-assets-fairing
is a Fairing for Rocket for easily serving static assets from a folder, with a nice cache policy.
Add to your Cargo.toml
:
rocket-assets-fairing = "0.1"
```rust use assetsrocketfairing::{Asset, Assets};
async fn main() { rocket::build() .attach(Assets::fairing()) .mount("/assets", routes![style]) .launch() .await; }
async fn style(assets: &Assets) -> Option
This is configurable the same way as Rocket.
Either through Rocket.toml
:
toml
[default]
assets_dir = "assets"
assets_max_age = 86400
Or using environment variables:
- ROCKET_ASSETS_DIR
- ROCKET_ASSETS_MAX_AGE