pub struct SpaMiddleware { /* private fields */ }Expand description
SPA static file middleware.
- Matches
/{filename}against the disk root, then against embedded files - Serves files with MIME types inferred by the host
- Falls back to
index.htmlfor unknown paths (SPA routing) - Handles GET and HEAD; other methods pass through silently
Implementations§
Source§impl SpaMiddleware
impl SpaMiddleware
Sourcepub fn new(source: impl Into<SpaSource>) -> SpaMiddleware
pub fn new(source: impl Into<SpaSource>) -> SpaMiddleware
Create a new SPA middleware with default index “index.html”.
The disk root is resolved relative to the current working directory.
If the directory doesn’t exist at that path, the middleware searches
upward through ancestor directories and their immediate subdirectories,
matching the strategy used by config::load_appsettings.
Sourcepub fn with_index(
source: impl Into<SpaSource>,
index: impl Into<String>,
) -> SpaMiddleware
pub fn with_index( source: impl Into<SpaSource>, index: impl Into<String>, ) -> SpaMiddleware
Create a new SPA middleware with a custom index file name.
Sourcepub fn from_source(source: SpaSource) -> SpaMiddleware
pub fn from_source(source: SpaSource) -> SpaMiddleware
Create a SPA middleware from an already-built source.
Sourcepub fn resolved_root(&self) -> &Path
pub fn resolved_root(&self) -> &Path
The disk directory actually consulted, after resolution.
Sourcepub fn embedded(&self) -> Option<&EmbeddedAssets>
pub fn embedded(&self) -> Option<&EmbeddedAssets>
The embedded files this middleware may serve, if any.
Present even when EMBED_ENV disabled them at runtime.
Trait Implementations§
Source§impl IMiddleware for SpaMiddleware
impl IMiddleware for SpaMiddleware
Source§fn invoke<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 mut dyn IHttpContext,
) -> Pin<Box<dyn Future<Output = Result<ControlFlow<()>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
SpaMiddleware: 'async_trait,
fn invoke<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 mut dyn IHttpContext,
) -> Pin<Box<dyn Future<Output = Result<ControlFlow<()>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
SpaMiddleware: 'async_trait,
Process an HTTP request (before hook). Read more
Auto Trait Implementations§
impl Freeze for SpaMiddleware
impl RefUnwindSafe for SpaMiddleware
impl Send for SpaMiddleware
impl Sync for SpaMiddleware
impl Unpin for SpaMiddleware
impl UnsafeUnpin for SpaMiddleware
impl UnwindSafe for SpaMiddleware
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more