pub struct SpaServer<T> { /* private fields */ }Expand description
A server wrapped axum server.
It can:
- serve static files in SPA root path
- serve API requests in router
- fallback to SPA static file when route matching failed
- if still get 404, it will redirect to SPA index.html
Implementations
sourceimpl<T> SpaServer<T> where
T: Clone + Sync + Send + 'static,
impl<T> SpaServer<T> where
T: Clone + Sync + Send + 'static,
sourcepub fn data(&mut self, data: T) -> &mut Self
pub fn data(&mut self, data: T) -> &mut Self
Specific server context data
This is similar to axum middleware
sourcepub async fn run<Root>(self, root: Root) -> Result<()> where
Root: SpaStatic,
pub async fn run<Root>(self, root: Root) -> Result<()> where
Root: SpaStatic,
Run the spa server forever
sourcepub fn route(&mut self, path: impl Into<String>, router: Router) -> &mut Self
pub fn route(&mut self, path: impl Into<String>, router: Router) -> &mut Self
Setting up server router, see example for usage.
sourcepub fn static_path(
&mut self,
path: impl Into<String>,
dir: impl Into<PathBuf>
) -> &mut Self
pub fn static_path(
&mut self,
path: impl Into<String>,
dir: impl Into<PathBuf>
) -> &mut Self
Setting up a runtime static file path.
Unlike spa_server_root, file in this path can be changed in runtime.
Trait Implementations
Auto Trait Implementations
impl<T> !RefUnwindSafe for SpaServer<T>
impl<T> Send for SpaServer<T> where
T: Send,
impl<T> !Sync for SpaServer<T>
impl<T> Unpin for SpaServer<T> where
T: Unpin,
impl<T> !UnwindSafe for SpaServer<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more