pub struct Server { /* private fields */ }Expand description
HTTP server that binds routes, middleware, and optional WebSocket handling.
Implementations§
Source§impl Server
impl Server
Sourcepub fn new(router: impl Into<Router>) -> Self
pub fn new(router: impl Into<Router>) -> Self
Create a server with default host/port and no global middleware.
Sourcepub fn from_config(router: impl Into<Router>) -> Self
pub fn from_config(router: impl Into<Router>) -> Self
Create a server from environment configuration, booting all services.
Sourcepub fn ws_interceptor<F>(self, handler: F) -> Self
pub fn ws_interceptor<F>(self, handler: F) -> Self
Set a WebSocket interceptor that runs before all routing.
The interceptor receives every WS upgrade request first.
Return Ok(response) to handle the connection; return Err(request) to
decline and let normal routing (including /_ferro/ws) proceed.
§Example
ⓘ
Server::from_config(router)
.ws_interceptor(|req| {
if req.uri().path().starts_with("/sessions/") {
Ok(my_ws_handler(req))
} else {
Err(req) // pass to /_ferro/ws
}
})
.run()
.await;Sourcepub fn middleware<M: Middleware + 'static>(self, middleware: M) -> Self
pub fn middleware<M: Middleware + 'static>(self, middleware: M) -> Self
Auto Trait Implementations§
impl Freeze for Server
impl !RefUnwindSafe for Server
impl Send for Server
impl Sync for Server
impl Unpin for Server
impl UnsafeUnpin for Server
impl !UnwindSafe for Server
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more