1
0
mirror of https://github.com/actix/examples synced 2024-12-01 01:24:35 +01:00
examples/hello-world/src/main.rs

29 lines
714 B
Rust
Raw Normal View History

extern crate actix;
extern crate actix_web;
extern crate env_logger;
2018-05-08 20:08:43 +02:00
use actix_web::{middleware, server, App, HttpRequest};
2018-07-16 08:36:53 +02:00
fn index(_req: &HttpRequest) -> &'static str {
"Hello world!"
}
fn main() {
::std::env::set_var("RUST_LOG", "actix_web=info");
env_logger::init();
let sys = actix::System::new("hello-world");
2018-05-08 20:08:43 +02:00
server::new(|| {
App::new()
// enable logger
.middleware(middleware::Logger::default())
.resource("/index.html", |r| r.f(|_| "Hello world!"))
2018-05-08 20:08:43 +02:00
.resource("/", |r| r.f(index))
}).bind("127.0.0.1:8080")
.unwrap()
.start();
println!("Started http server: 127.0.0.1:8080");
let _ = sys.run();
}