pub struct SpaMiddleware { /* private fields */ }Expand description
SPA static file middleware.
- Matches
/{filename}against local filesystem - Serves files with auto-detected MIME types
- Falls back to
index.htmlfor unknown paths (SPA routing) - Only handles GET requests; non-GET passes through silently
Implementations§
Source§impl SpaMiddleware
impl SpaMiddleware
Sourcepub fn new(root: impl Into<PathBuf>) -> SpaMiddleware
pub fn new(root: impl Into<PathBuf>) -> SpaMiddleware
Create a new SPA middleware with default index “index.html”.
The root path 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(
root: impl Into<PathBuf>,
index: impl Into<String>,
) -> SpaMiddleware
pub fn with_index( root: impl Into<PathBuf>, index: impl Into<String>, ) -> SpaMiddleware
Create a new SPA middleware with a custom index file name.
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