1
0
mirror of https://github.com/actix/examples synced 2025-02-09 20:25:37 +01:00
2020-04-09 01:54:28 +01:00

37 lines
840 B
Rust

use log::info;
use actix_files::Files;
use actix_web::{web, App, Error, HttpRequest, HttpResponse, HttpServer};
use actix_web_actors::ws;
mod message;
mod server;
mod session;
use session::WsChatSession;
async fn chat_route(
req: HttpRequest,
stream: web::Payload,
) -> Result<HttpResponse, Error> {
ws::start(WsChatSession::default(), &req, stream)
}
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
env_logger::from_env(env_logger::Env::default().default_filter_or("info")).init();
let addr = "127.0.0.1:8080";
let srv = HttpServer::new(move || {
App::new()
.service(web::resource("/ws/").to(chat_route))
.service(Files::new("/", "./static/").index_file("index.html"))
})
.bind(&addr)?;
info!("Starting http server: {}", &addr);
srv.run().await
}