Struct memory_serve::MemoryServe
source · pub struct MemoryServe { /* private fields */ }
Expand description
Helper struct to create and configure an axum to serve static files from
memory.
Initiate an instance with the MemoryServe::new
method and pass a call
to the load_assets!
macro as the single argument.
Implementations§
source§impl MemoryServe
impl MemoryServe
sourcepub fn new(assets: &'static [Asset]) -> Self
pub fn new(assets: &'static [Asset]) -> Self
Initiate a MemoryServe
instance, takes the output of load_assets!
as an argument. load_assets!
takes a directory name relative from
the project root.
sourcepub fn index_file(self, index_file: Option<&'static str>) -> Self
pub fn index_file(self, index_file: Option<&'static str>) -> Self
Which static file to serve on the route “/” (the index)
The path (or route) should be relative to the directory passed to
the load_assets!
macro, but prepended with a slash.
By default this is Some("/index.html")
sourcepub fn fallback(self, fallback: Option<&'static str>) -> Self
pub fn fallback(self, fallback: Option<&'static str>) -> Self
Which static file to serve when no other routes are matched, also see
fallback
The path (or route) should be relative to the directory passed to
the load_assets!
macro, but prepended with a slash.
By default this is None
, which means axum will return an empty
response with a HTTP 404 status code when no route matches.
sourcepub fn fallback_status(self, fallback_status: StatusCode) -> Self
pub fn fallback_status(self, fallback_status: StatusCode) -> Self
What HTTP status code to return when a static file is returned by the fallback handler.
sourcepub fn enable_gzip(self, enable_gzip: bool) -> Self
pub fn enable_gzip(self, enable_gzip: bool) -> Self
Whether to enable gzip compression. When set to true
, clients that
accept gzip compressed files, but not brotli compressed files,
are served gzip compressed files.
sourcepub fn enable_brotli(self, enable_brotli: bool) -> Self
pub fn enable_brotli(self, enable_brotli: bool) -> Self
Whether to enable brotli compression. When set to true
, clients that
accept brotli compressed files are served brotli compressed files.
sourcepub fn html_cache_control(self, html_cache_control: CacheControl) -> Self
pub fn html_cache_control(self, html_cache_control: CacheControl) -> Self
The Cache-Control header to set for HTML files. See Cache control for options.
sourcepub fn cache_control(self, cache_control: CacheControl) -> Self
pub fn cache_control(self, cache_control: CacheControl) -> Self
Cache header to non-HTML files. See Cache control for options.