1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-01-31 02:52:53 +01:00

48 lines
1.2 KiB
Rust
Raw Normal View History

2017-12-28 11:36:20 -08:00
extern crate actix;
extern crate actix_web;
extern crate futures;
extern crate env_logger;
2017-12-28 16:25:47 -08:00
use actix::*;
2017-12-28 11:36:20 -08:00
use actix_web::*;
2017-12-31 21:55:25 -08:00
#[cfg(unix)]
use actix::actors::signal::{ProcessSignals, Subscribe};
2017-12-28 11:36:20 -08:00
2017-12-28 16:25:47 -08:00
struct MyWebSocket;
impl Actor for MyWebSocket {
type Context = HttpContext<Self>;
}
impl StreamHandler<ws::Message> for MyWebSocket {}
impl Handler<ws::Message> for MyWebSocket {
fn handle(&mut self, _: ws::Message, _: &mut Self::Context) -> Response<Self, ws::Message> {
Self::empty()
}
}
2017-12-28 11:36:20 -08:00
fn main() {
::std::env::set_var("RUST_LOG", "actix_web=info");
let _ = env_logger::init();
let sys = actix::System::new("signals-example");
let addr = HttpServer::new(|| {
Application::new()
// enable logger
.middleware(middleware::Logger::default())
2017-12-28 16:25:47 -08:00
.resource("/ws/", |r| r.f(|req| ws::start(req, MyWebSocket)))
2017-12-28 11:36:20 -08:00
.resource("/", |r| r.h(httpcodes::HTTPOk))})
.bind("127.0.0.1:8080").unwrap()
.start();
2017-12-31 21:55:25 -08:00
// Subscribe to unix signals
#[cfg(unix)]
{
let signals = Arbiter::system_registry().get::<ProcessSignals>();
signals.send(Subscribe(addr.subscriber()));
}
2017-12-28 11:36:20 -08:00
println!("Started http server: 127.0.0.1:8080");
let _ = sys.run();
}