mirror of
https://github.com/actix/examples
synced 2024-11-27 16:02:57 +01:00
docs: tweak comment on actorless ws mains
This commit is contained in:
parent
942e8ed173
commit
bf22fecbcd
@ -2,6 +2,8 @@
|
|||||||
//!
|
//!
|
||||||
//! Open `http://localhost:8080/` in browser to test.
|
//! Open `http://localhost:8080/` in browser to test.
|
||||||
|
|
||||||
|
use std::io;
|
||||||
|
|
||||||
use actix_files::NamedFile;
|
use actix_files::NamedFile;
|
||||||
use actix_web::{middleware, web, App, Error, HttpRequest, HttpResponse, HttpServer, Responder};
|
use actix_web::{middleware, web, App, Error, HttpRequest, HttpResponse, HttpServer, Responder};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
@ -45,9 +47,9 @@ async fn chat_ws(
|
|||||||
Ok(res)
|
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")]
|
#[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"));
|
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||||
|
|
||||||
log::info!("starting HTTP server at http://localhost:8080");
|
log::info!("starting HTTP server at http://localhost:8080");
|
||||||
@ -63,7 +65,8 @@ async fn main() -> std::io::Result<()> {
|
|||||||
.service(web::resource("/").to(index))
|
.service(web::resource("/").to(index))
|
||||||
// websocket routes
|
// websocket routes
|
||||||
.service(web::resource("/ws").route(web::get().to(chat_ws)))
|
.service(web::resource("/ws").route(web::get().to(chat_ws)))
|
||||||
// enable logger
|
// standard middleware
|
||||||
|
.wrap(middleware::NormalizePath::trim())
|
||||||
.wrap(middleware::Logger::default())
|
.wrap(middleware::Logger::default())
|
||||||
})
|
})
|
||||||
.workers(2)
|
.workers(2)
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
//!
|
//!
|
||||||
//! Open `http://localhost:8080/` in browser to test.
|
//! Open `http://localhost:8080/` in browser to test.
|
||||||
|
|
||||||
|
use std::io;
|
||||||
|
|
||||||
use actix_files::NamedFile;
|
use actix_files::NamedFile;
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
middleware, rt, web, App, Error, HttpRequest, HttpResponse, HttpServer, Responder,
|
middleware, rt, web, App, Error, HttpRequest, HttpResponse, HttpServer, Responder,
|
||||||
@ -63,9 +65,9 @@ async fn broadcast_ws(
|
|||||||
Ok(res)
|
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")]
|
#[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"));
|
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||||
|
|
||||||
log::info!("starting HTTP server at http://localhost:8080");
|
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()))
|
.app_data(web::Data::new(tx.clone()))
|
||||||
.service(web::resource("/ws-broadcast").route(web::get().to(broadcast_ws)))
|
.service(web::resource("/ws-broadcast").route(web::get().to(broadcast_ws)))
|
||||||
.service(web::resource("/send").route(web::post().to(send_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())
|
.wrap(middleware::Logger::default())
|
||||||
})
|
})
|
||||||
.workers(2)
|
.workers(2)
|
||||||
|
Loading…
Reference in New Issue
Block a user