Trait WebServerAppExt

Source
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_webserver::{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§

Source

fn add_server(&mut self, ip: IpAddr, port: WebPort) -> &mut Self

Add a server on specific IP and port

Source

fn update_server( &mut self, ip: IpAddr, port: WebPort, router: Router, ) -> WebServerResult<&mut Self>

Update a server configuration at runtime

Source

fn remove_server(&mut self, port: WebPort) -> WebServerResult<&mut Self>

Remove a server

Source

fn port_route( &mut self, port: WebPort, path: &str, method_router: MethodRouter<()>, ) -> &mut Self

Add a route to a specific port

Source

fn port_router( &mut self, port: WebPort, router_fn: impl FnOnce(Router) -> Router, ) -> &mut Self

Configure router for specific port

Source

fn port_nest( &mut self, port: WebPort, path: &str, router: Router<()>, ) -> &mut Self

Add nested routes to a specific port

Source

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,

Add a service to a specific port

Source

fn port_merge<R>(&mut self, port: WebPort, other: R) -> &mut Self
where R: Into<Router<()>>,

Merge another router into a specific port

Source

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,

Add a layer to a specific port

Source

fn port_fallback<H, T>(&mut self, port: WebPort, handler: H) -> &mut Self
where H: Handler<T, ()>, T: 'static,

Add a fallback handler to a specific port

Source

fn running_servers(&self) -> Vec<(WebPort, IpAddr)>

Get information about running servers

Source

fn routed_ports(&self) -> Vec<WebPort>

All configured ports

Source

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", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl WebServerAppExt for App

Source§

fn add_server(&mut self, ip: IpAddr, port: WebPort) -> &mut Self

Source§

fn update_server( &mut self, ip: IpAddr, port: WebPort, router: Router, ) -> WebServerResult<&mut Self>

Source§

fn remove_server(&mut self, port: WebPort) -> WebServerResult<&mut Self>

Source§

fn port_route( &mut self, port: WebPort, path: &str, method_router: MethodRouter<()>, ) -> &mut Self

Source§

fn port_router( &mut self, port: WebPort, router_fn: impl FnOnce(Router) -> Router, ) -> &mut Self

Source§

fn port_nest( &mut self, port: WebPort, path: &str, router: Router<()>, ) -> &mut Self

Source§

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,

Source§

fn port_merge<R>(&mut self, port: WebPort, other: R) -> &mut Self
where R: Into<Router<()>>,

Source§

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,

Source§

fn port_fallback<H, T>(&mut self, port: WebPort, handler: H) -> &mut Self
where H: Handler<T, ()>, T: 'static,

Source§

fn running_servers(&self) -> Vec<(WebPort, IpAddr)>

Source§

fn routed_ports(&self) -> Vec<WebPort>

Source§

fn server_count(&self) -> usize

Implementors§