Static file serving
Trillium offers two rudimentary approaches to static file serving for now. Neither of these approaches perform any cache-related header checking yet.
From disk
This handler loads content from disk at request, and does not yet do any in-memory caching.
#[cfg(unix)]
pub fn main() {
use trillium_static::{crate_relative_path, files};
trillium_smol::run((
trillium_logger::logger(),
files(crate_relative_path!("examples/files")).with_index_file("index.html"),
))
}
#[cfg(not(unix))]
pub fn main() {}
From memory, at compile time
This handler includes all of the static content in the compiled binary, allowing it to be shipped independently from the assets.
#[cfg(unix)]
pub fn main() {
use trillium_static_compiled::static_compiled;
trillium_smol::run((
trillium_logger::Logger::new(),
trillium_caching_headers::CachingHeaders::new(),
static_compiled!("./examples/files").with_index_file("index.html"),
));
}
#[cfg(not(unix))]
pub fn main() {}