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

22 lines
578 B
Rust
Raw Normal View History

2019-03-10 07:38:15 +01:00
use actix_web::{middleware, web, App, HttpRequest, HttpServer};
2019-03-10 07:38:15 +01:00
fn index(req: HttpRequest) -> &'static str {
println!("REQ: {:?}", req);
"Hello world!"
}
2019-03-10 07:38:15 +01:00
fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "actix_web=info");
env_logger::init();
2019-03-10 07:38:15 +01:00
HttpServer::new(|| {
2018-05-08 20:08:43 +02:00
App::new()
// enable logger
.middleware(middleware::Logger::default())
2019-03-10 07:38:15 +01:00
.service(web::resource("/index.html").to(|| "Hello world!"))
.service(web::resource("/").to(index))
2019-03-10 03:03:09 +01:00
})
2019-03-10 07:38:15 +01:00
.bind("127.0.0.1:8080")?
.run()
}