1
0
mirror of https://github.com/actix/examples synced 2025-06-28 09:50:36 +02:00

Update to master (#90)

This commit is contained in:
Juan Aguilar
2019-03-26 04:29:00 +01:00
committed by Douman
parent 1779f963d9
commit 53fc2221ef
44 changed files with 139 additions and 143 deletions

View File

@ -15,9 +15,9 @@ path = "src/main.rs"
[dependencies]
actix = { git="https://github.com/actix/actix.git" }
actix-web = { git="https://github.com/actix/actix-web.git", branch = "1.0" }
actix-web-actors = { git="https://github.com/actix/actix-web.git", branch = "1.0" }
actix-files = { git="https://github.com/actix/actix-web.git", branch = "1.0" }
actix-web = { git="https://github.com/actix/actix-web.git" }
actix-web-actors = { git="https://github.com/actix/actix-web.git" }
actix-files = { git="https://github.com/actix/actix-web.git" }
env_logger = "0.6"
futures = "0.1"
bytes = "0.4"

View File

@ -7,12 +7,8 @@ use std::time::{Duration, Instant};
use actix::prelude::*;
use actix_files as fs;
use actix_web::{
error, middleware, web, App, Error, HttpRequest, HttpResponse, HttpServer,
};
use actix_web::{middleware, web, App, Error, HttpRequest, HttpResponse, HttpServer};
use actix_web_actors::ws;
use bytes::Bytes;
use futures::Stream;
/// How often heartbeat pings are sent
const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5);
@ -20,10 +16,7 @@ const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5);
const CLIENT_TIMEOUT: Duration = Duration::from_secs(10);
/// do websocket handshake and start `MyWebSocket` actor
fn ws_index<S>(r: HttpRequest, stream: web::Payload<S>) -> Result<HttpResponse, Error>
where
S: Stream<Item = Bytes, Error = error::PayloadError> + 'static,
{
fn ws_index(r: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> {
println!("{:?}", r);
let res = ws::start(MyWebSocket::new(), &r, stream);
println!("{:?}", res.as_ref().unwrap());
@ -103,7 +96,7 @@ fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
// enable logger
.middleware(middleware::Logger::default())
.wrap(middleware::Logger::default())
// websocket route
.service(web::resource("/ws/").route(web::get().to(ws_index)))
// static files