#[cfg(all(feature = "axum", feature = "ws"))]
#[tokio::main]
async fn main() {
use futures::sink::SinkExt;
use httpz::{
http::Method,
ws::{Message, WebsocketUpgrade},
GenericEndpoint, Request,
};
let endpoint = GenericEndpoint::new(
"/",
[Method::GET, Method::POST],
|req: Request| async move {
WebsocketUpgrade::from_req(req, |_req, mut socket| async move {
socket
.send(Message::Text("Hello World".to_string()))
.await
.unwrap();
})
},
);
#[cfg(feature = "cookies")]
let endpoint2 = GenericEndpoint::new(
"/",
[Method::GET, Method::POST],
|req: Request| async move {
WebsocketUpgrade::from_req(req, |_req, mut socket| async move {
socket
.send(Message::Text("Hello World".to_string()))
.await
.unwrap();
})
},
);
let app = axum::Router::new().nest("/", endpoint.axum());
#[cfg(feature = "cookies")]
let app = app.nest("/cookiesws", endpoint2.axum());
let addr = "[::]:9000".parse::<std::net::SocketAddr>().unwrap(); println!("Axum listening on http://{}", addr);
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
}