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§
Source§impl<T> SpaServer<T>
impl<T> SpaServer<T>
Sourcepub fn data(self, data: T) -> Self
pub fn data(self, data: T) -> Self
Specific server context data
This is similar to axum middleware
Sourcepub fn layer<L, NewResBody>(self, layer: L) -> Selfwhere
L: Layer<Route> + Clone + Send + 'static,
L::Service: Service<Request, Response = Response<NewResBody>, Error = Infallible> + Clone + Send + 'static,
<L::Service as Service<Request>>::Future: Send + 'static,
NewResBody: HttpBody<Data = Bytes> + Send + 'static,
NewResBody::Error: Into<BoxError>,
pub fn layer<L, NewResBody>(self, layer: L) -> Selfwhere
L: Layer<Route> + Clone + Send + 'static,
L::Service: Service<Request, Response = Response<NewResBody>, Error = Infallible> + Clone + Send + 'static,
<L::Service as Service<Request>>::Future: Send + 'static,
NewResBody: HttpBody<Data = Bytes> + Send + 'static,
NewResBody::Error: Into<BoxError>,
Specific an axum layer to server
This is similar to axum middleware
Sourcepub fn release_path(self, rp: impl Into<PathBuf>) -> Self
pub fn release_path(self, rp: impl Into<PathBuf>) -> Self
static file release path in runtime
Default path is /tmp/[env!(CARGO_PKG_NAME)]_static_files
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(self, path: impl AsRef<str>, router: Router) -> Self
pub fn route(self, path: impl AsRef<str>, router: Router) -> Self
Setting up server router, see example for usage.
Sourcepub fn static_path(
self,
path: impl Into<String>,
dir: impl Into<PathBuf>,
) -> Self
pub fn static_path( self, path: impl Into<String>, dir: impl Into<PathBuf>, ) -> Self
Setting up a runtime static file path.
Unlike spa_server_root, file in this path can be changed in runtime.
Sourcepub fn host_router(self, host: impl Into<String>, router: Router) -> Self
pub fn host_router(self, host: impl Into<String>, router: Router) -> Self
add host based router
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for SpaServer<T>where
T: Freeze,
impl<T = ()> !RefUnwindSafe for SpaServer<T>
impl<T = ()> !Send for SpaServer<T>
impl<T = ()> !Sync for SpaServer<T>
impl<T> Unpin for SpaServer<T>where
T: Unpin,
impl<T = ()> !UnwindSafe for SpaServer<T>
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