From 653b4318955b8397635d2695b4316ed8898584bf Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 13 Dec 2017 17:28:16 -0800 Subject: [PATCH] fix example --- examples/websocket-chat/src/main.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/examples/websocket-chat/src/main.rs b/examples/websocket-chat/src/main.rs index 7547b505d..b553b5f24 100644 --- a/examples/websocket-chat/src/main.rs +++ b/examples/websocket-chat/src/main.rs @@ -192,23 +192,27 @@ fn main() { Ok(()) })); - // Websocket sessions state - let state = WsChatSessionState { addr: server }; // Create Http server with websocket support HttpServer::new( - Application::with_state("/", state) + move || { + // Websocket sessions state + let state = WsChatSessionState { addr: server.clone() }; + + Application::with_state(state) // redirect to websocket.html - .resource("/", |r| r.method(Method::GET).f(|req| { - httpcodes::HTTPFound - .build() - .header("LOCATION", "/static/websocket.html") - .body(Body::Empty) - })) + .resource("/", |r| r.method(Method::GET).f(|req| { + httpcodes::HTTPFound + .build() + .header("LOCATION", "/static/websocket.html") + .body(Body::Empty) + })) // websocket - .resource("/ws/", |r| r.route().f(chat_route)) + .resource("/ws/", |r| r.route().f(chat_route)) // static resources - .resource("/static", |r| r.h(fs::StaticFiles::new("static/", true)))) + .resource("/static/{tail:.*}", + |r| r.h(fs::StaticFiles::new("tail", "static/", true))) + }) .serve::<_, ()>("127.0.0.1:8080").unwrap(); let _ = sys.run();