pub struct StaticOptions { /* private fields */ }Expand description
How a directory is served, see App::serve_static_with
use ullun::static_files::StaticOptions;
// a single-page app built by a bundler
let options = StaticOptions::new()
.precompressed() // use app.js.br / app.js.gz when the client accepts them
.immutable_dir("assets") // assets/* never change under the same name
.spa_fallback("index.html"); // /orders/17 -> index.html for browsersImplementations§
Source§impl StaticOptions
impl StaticOptions
pub fn new() -> Self
Sourcepub fn cache_control(self, value: &str) -> Self
pub fn cache_control(self, value: &str) -> Self
Cache-Control for ordinary files (default public, max-age=3600)
Sourcepub fn precompressed(self) -> Self
pub fn precompressed(self) -> Self
Serve file.br or file.gz next to file when the client accepts that
encoding (Brotli preferred), with Content-Encoding and Vary: Accept-Encoding.
Compress at build time; nothing is compressed per request.
Sourcepub fn spa_fallback(self, file: &str) -> Self
pub fn spa_fallback(self, file: &str) -> Self
Answer navigations to unknown paths (GET accepting text/html, no file
extension) with this file, usually index.html, so client-side routes
survive a reload. Missing assets (/app.js) still give 404.
Sourcepub fn immutable_dir(self, dir: &str) -> Self
pub fn immutable_dir(self, dir: &str) -> Self
Files under this directory (relative to the root) are cached for a year
and marked immutable: use it for bundler output whose names change with content
Sourcepub fn hashed_names(self) -> Self
pub fn hashed_names(self) -> Self
Treat files whose name contains a content hash (a dot- or dash-separated
segment of 8 or more hex digits, at least one a digit, as in
app.3f9a2c1b.js) as immutable