pub struct MemoryServe { /* private fields */ }Expand description
Helper struct to create and configure an axum to serve static files from memory.
Implementations§
Source§impl MemoryServe
impl MemoryServe
Sourcepub fn new(assets: &'static [Asset]) -> Self
pub fn new(assets: &'static [Asset]) -> Self
Initiate a MemoryServe instance, taking the output of the load!
macro as an argument. load! selects the assets prepared during the
build step.
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 set with
the ASSET_DIR variable, but prepended with a slash.
By default this is Some("/index.html")
Sourcepub fn index_on_subdirectories(self, enable: bool) -> Self
pub fn index_on_subdirectories(self, enable: bool) -> Self
Whether to serve the corresponding index.html file when a route matches a subdirectory
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 set with
the ASSET_DIR variable, 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 enable_clean_url(self, enable_clean_url: bool) -> Self
pub fn enable_clean_url(self, enable_clean_url: bool) -> Self
Whether to enable clean URLs. When set to true, the routing path for
HTML files will not include the extension so that a file located at
“/about.html” maps to “/about” instead of “/about.html”.
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.