From bf22fecbcded28d5884eaadaa335c44b540632d2 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sun, 21 Jul 2024 09:42:28 +0100 Subject: [PATCH] docs: tweak comment on actorless ws mains --- websockets/chat-actorless/src/main.rs | 9 ++++++--- websockets/echo-actorless/src/main.rs | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/websockets/chat-actorless/src/main.rs b/websockets/chat-actorless/src/main.rs index b5890da9..c5cd1441 100644 --- a/websockets/chat-actorless/src/main.rs +++ b/websockets/chat-actorless/src/main.rs @@ -2,6 +2,8 @@ //! //! Open `http://localhost:8080/` in browser to test. +use std::io; + use actix_files::NamedFile; use actix_web::{middleware, web, App, Error, HttpRequest, HttpResponse, HttpServer, Responder}; use tokio::{ @@ -45,9 +47,9 @@ async fn chat_ws( Ok(res) } -// note that the `actix` based WebSocket handling would NOT work under `tokio::main` +// note that the actor-based WebSocket examples would NOT work under `tokio::main` #[tokio::main(flavor = "current_thread")] -async fn main() -> std::io::Result<()> { +async fn main() -> io::Result<()> { env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); log::info!("starting HTTP server at http://localhost:8080"); @@ -63,7 +65,8 @@ async fn main() -> std::io::Result<()> { .service(web::resource("/").to(index)) // websocket routes .service(web::resource("/ws").route(web::get().to(chat_ws))) - // enable logger + // standard middleware + .wrap(middleware::NormalizePath::trim()) .wrap(middleware::Logger::default()) }) .workers(2) diff --git a/websockets/echo-actorless/src/main.rs b/websockets/echo-actorless/src/main.rs index 8e7b34e9..fb8abcbe 100644 --- a/websockets/echo-actorless/src/main.rs +++ b/websockets/echo-actorless/src/main.rs @@ -2,6 +2,8 @@ //! //! Open `http://localhost:8080/` in browser to test. +use std::io; + use actix_files::NamedFile; use actix_web::{ middleware, rt, web, App, Error, HttpRequest, HttpResponse, HttpServer, Responder, @@ -63,9 +65,9 @@ async fn broadcast_ws( Ok(res) } -// note that the `actix` based WebSocket handling would NOT work under `tokio::main` +// note that the actor-based WebSocket examples would NOT work under `tokio::main` #[tokio::main(flavor = "current_thread")] -async fn main() -> std::io::Result<()> { +async fn main() -> io::Result<()> { env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); log::info!("starting HTTP server at http://localhost:8080"); @@ -82,7 +84,8 @@ async fn main() -> std::io::Result<()> { .app_data(web::Data::new(tx.clone())) .service(web::resource("/ws-broadcast").route(web::get().to(broadcast_ws))) .service(web::resource("/send").route(web::post().to(send_to_broadcast_ws))) - // enable logger + // standard middleware + .wrap(middleware::NormalizePath::trim()) .wrap(middleware::Logger::default()) }) .workers(2)