pub trait WebServerAppExt {
Show 13 methods
// Required methods
fn add_server(&mut self, ip: IpAddr, port: WebPort) -> &mut Self;
fn update_server(
&mut self,
ip: IpAddr,
port: WebPort,
router: Router,
) -> WebServerResult<&mut Self>;
fn remove_server(&mut self, port: WebPort) -> WebServerResult<&mut Self>;
fn port_route(
&mut self,
port: WebPort,
path: &str,
method_router: MethodRouter<()>,
) -> &mut Self;
fn port_router(
&mut self,
port: WebPort,
router_fn: impl FnOnce(Router) -> Router,
) -> &mut Self;
fn port_nest(
&mut self,
port: WebPort,
path: &str,
router: Router<()>,
) -> &mut Self;
fn port_route_service<T>(
&mut self,
port: WebPort,
path: &str,
service: T,
) -> &mut Self
where T: Service<Request, Error = Infallible> + Clone + Send + Sync + 'static,
T::Response: IntoResponse,
T::Future: Send + 'static;
fn port_merge<R>(&mut self, port: WebPort, other: R) -> &mut Self
where R: Into<Router<()>>;
fn port_layer<L>(&mut self, port: WebPort, layer: L) -> &mut Self
where L: Layer<Route> + Clone + Send + Sync + 'static,
L::Service: Service<Request> + Clone + Send + Sync + 'static,
<L::Service as Service<Request>>::Response: IntoResponse + 'static,
<L::Service as Service<Request>>::Error: Into<Infallible> + 'static,
<L::Service as Service<Request>>::Future: Send + 'static;
fn port_fallback<H, T>(&mut self, port: WebPort, handler: H) -> &mut Self
where H: Handler<T, ()>,
T: 'static;
fn running_servers(&self) -> Vec<(WebPort, IpAddr)>;
fn routed_ports(&self) -> Vec<WebPort> ⓘ;
fn server_count(&self) -> usize;
}Expand description
Extends Bevy App with multi-port web server capabilities and server management.
This trait provides methods for managing multiple web servers on different ports, configuring port-specific routing, and managing server lifecycle.
§Examples
use bevy::prelude::*;
use bevy_webgate::{WebServerAppExt, BevyWebServerPlugin};
use axum::routing::get;
let mut app = App::new();
app.add_plugins(MinimalPlugins)
.add_plugins(BevyWebServerPlugin);
// Multi-port usage
app.port_route(8081, "/admin", get(|| async { "Admin" }))
.port_route(8082, "/health", get(|| async { "OK" }));
// Custom IP binding
app.add_server("127.0.0.1".parse().unwrap(), 8083);Required Methods§
Sourcefn add_server(&mut self, ip: IpAddr, port: WebPort) -> &mut Self
fn add_server(&mut self, ip: IpAddr, port: WebPort) -> &mut Self
Add a server on specific IP and port
Sourcefn update_server(
&mut self,
ip: IpAddr,
port: WebPort,
router: Router,
) -> WebServerResult<&mut Self>
fn update_server( &mut self, ip: IpAddr, port: WebPort, router: Router, ) -> WebServerResult<&mut Self>
Update a server configuration at runtime
Sourcefn remove_server(&mut self, port: WebPort) -> WebServerResult<&mut Self>
fn remove_server(&mut self, port: WebPort) -> WebServerResult<&mut Self>
Remove a server
Sourcefn port_route(
&mut self,
port: WebPort,
path: &str,
method_router: MethodRouter<()>,
) -> &mut Self
fn port_route( &mut self, port: WebPort, path: &str, method_router: MethodRouter<()>, ) -> &mut Self
Add a route to a specific port
Sourcefn port_router(
&mut self,
port: WebPort,
router_fn: impl FnOnce(Router) -> Router,
) -> &mut Self
fn port_router( &mut self, port: WebPort, router_fn: impl FnOnce(Router) -> Router, ) -> &mut Self
Configure router for specific port
Sourcefn port_nest(
&mut self,
port: WebPort,
path: &str,
router: Router<()>,
) -> &mut Self
fn port_nest( &mut self, port: WebPort, path: &str, router: Router<()>, ) -> &mut Self
Add nested routes to a specific port
Sourcefn port_route_service<T>(
&mut self,
port: WebPort,
path: &str,
service: T,
) -> &mut Selfwhere
T: Service<Request, Error = Infallible> + Clone + Send + Sync + 'static,
T::Response: IntoResponse,
T::Future: Send + 'static,
fn port_route_service<T>(
&mut self,
port: WebPort,
path: &str,
service: T,
) -> &mut Selfwhere
T: Service<Request, Error = Infallible> + Clone + Send + Sync + 'static,
T::Response: IntoResponse,
T::Future: Send + 'static,
Add a service to a specific port
Sourcefn port_merge<R>(&mut self, port: WebPort, other: R) -> &mut Self
fn port_merge<R>(&mut self, port: WebPort, other: R) -> &mut Self
Merge another router into a specific port
Sourcefn port_layer<L>(&mut self, port: WebPort, layer: L) -> &mut Selfwhere
L: Layer<Route> + Clone + Send + Sync + 'static,
L::Service: Service<Request> + Clone + Send + Sync + 'static,
<L::Service as Service<Request>>::Response: IntoResponse + 'static,
<L::Service as Service<Request>>::Error: Into<Infallible> + 'static,
<L::Service as Service<Request>>::Future: Send + 'static,
fn port_layer<L>(&mut self, port: WebPort, layer: L) -> &mut Selfwhere
L: Layer<Route> + Clone + Send + Sync + 'static,
L::Service: Service<Request> + Clone + Send + Sync + 'static,
<L::Service as Service<Request>>::Response: IntoResponse + 'static,
<L::Service as Service<Request>>::Error: Into<Infallible> + 'static,
<L::Service as Service<Request>>::Future: Send + 'static,
Add a layer to a specific port
Sourcefn port_fallback<H, T>(&mut self, port: WebPort, handler: H) -> &mut Self
fn port_fallback<H, T>(&mut self, port: WebPort, handler: H) -> &mut Self
Add a fallback handler to a specific port
Sourcefn running_servers(&self) -> Vec<(WebPort, IpAddr)>
fn running_servers(&self) -> Vec<(WebPort, IpAddr)>
Get information about running servers
Sourcefn routed_ports(&self) -> Vec<WebPort> ⓘ
fn routed_ports(&self) -> Vec<WebPort> ⓘ
All configured ports
Sourcefn server_count(&self) -> usize
fn server_count(&self) -> usize
Get the number of configured servers
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".