diff --git a/server/src/server.rs b/server/src/server.rs index 5700f9d8d708b6e8c0c93166184149546b1b9a35..1c131e47f1e62e0d267e6601d05dfec6b910d53c 100644 --- a/server/src/server.rs +++ b/server/src/server.rs @@ -12,6 +12,7 @@ use actix_files::NamedFile; use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Responder}; use actix_web_actors::ws; +/// Serve `index.html` for path `/`. async fn index(cfg: web::Data) -> Result { let full_path = cfg.static_files.join("index.html"); @@ -20,6 +21,7 @@ async fn index(cfg: web::Data) -> Result { Ok(file.use_last_modified(true)) } +/// Create Subscriber/Publisher WebSocket actors. async fn ws( cfg: web::Data, rooms: web::Data>, @@ -42,6 +44,7 @@ async fn ws( } } +/// Serve static files (`index.html`, JavaScript, CSS, etc). async fn static_file( cfg: web::Data, req: HttpRequest, @@ -54,6 +57,7 @@ async fn static_file( Ok(file.use_last_modified(true)) } +/// Start the server based on the passed `Config`. pub async fn run(cfg: Config) -> Result<(), anyhow::Error> { let rooms = Rooms::new().start(); @@ -62,7 +66,7 @@ pub async fn run(cfg: Config) -> Result<(), anyhow::Error> { let server = HttpServer::new(move || { App::new() - .app_data(cfg_clone.clone()) + .data(cfg_clone.clone()) .data(rooms.clone()) .route("/", web::get().to(index)) .route("/ws/{mode:(publish|subscribe)}", web::get().to(ws))