Crates.io | rocket-assets-fairing |
lib.rs | rocket-assets-fairing |
version | 0.1.0 |
source | src |
created_at | 2022-01-08 17:24:36.12375 |
updated_at | 2022-01-08 17:24:36.12375 |
description | A rocket fairing for easily serving static with cache policy from a configurable directory |
homepage | |
repository | https://github.com/misterio77/rocket-assets-fairing |
max_upload_size | |
id | 510355 |
size | 8,091 |
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"
use assets_rocket_fairing::{Asset, Assets};
#[rocket::main]
async fn main() {
rocket::build()
.attach(Assets::fairing())
.mount("/assets", routes![style])
.launch()
.await;
}
#[get("/style.css")]
async fn style(assets: &Assets) -> Option<Asset> {
assets.open("style.css").await.ok()
}
This is configurable the same way as Rocket.
Either through Rocket.toml
:
[default]
assets_dir = "assets"
assets_max_age = 86400
Or using environment variables:
ROCKET_ASSETS_DIR
ROCKET_ASSETS_MAX_AGE