1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-24 16:32:59 +01:00
actix-web/examples/unix-socket/src/main.rs

33 lines
856 B
Rust
Raw Normal View History

2018-03-05 14:09:13 +01:00
extern crate actix;
extern crate actix_web;
extern crate env_logger;
extern crate tokio_uds;
use actix::*;
use actix_web::*;
use tokio_uds::UnixListener;
fn index(_req: HttpRequest) -> &'static str {
"Hello world!"
}
fn main() {
::std::env::set_var("RUST_LOG", "actix_web=info");
2018-03-31 09:16:55 +02:00
env_logger::init();
2018-03-05 14:09:13 +01:00
let sys = actix::System::new("unix-socket");
2018-03-31 09:16:55 +02:00
let listener = UnixListener::bind(
"/tmp/actix-uds.socket", Arbiter::handle()).expect("bind failed");
HttpServer::new(
|| App::new()
2018-03-05 14:09:13 +01:00
// enable logger
.middleware(middleware::Logger::default())
.resource("/index.html", |r| r.f(|_| "Hello world!"))
.resource("/", |r| r.f(index)))
.start_incoming(listener.incoming(), false);
println!("Started http server: /tmp/actix-uds.socket");
let _ = sys.run();
}