1
0
mirror of https://github.com/actix/examples synced 2025-02-09 20:25:37 +01:00

22 lines
572 B
Rust
Raw Normal View History

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