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

46 lines
1.2 KiB
Rust
Raw Normal View History

2019-09-11 14:04:33 +02:00
use actix_service::Service;
2019-12-07 23:59:24 +06:00
use actix_web::{web, App, HttpServer};
use futures::future::FutureExt;
2018-07-09 20:18:31 +02:00
2018-07-09 21:36:03 +02:00
#[allow(dead_code)]
mod read_request_body;
#[allow(dead_code)]
mod read_response_body;
#[allow(dead_code)]
2019-12-07 23:59:24 +06:00
mod redirect;
#[allow(dead_code)]
2018-07-09 20:18:31 +02:00
mod simple;
2019-12-07 23:59:24 +06:00
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
2019-03-10 19:19:50 -07:00
std::env::set_var("RUST_LOG", "actix_web=debug");
env_logger::init();
2018-07-09 20:18:31 +02:00
2019-03-10 19:19:50 -07:00
HttpServer::new(|| {
2018-07-09 20:18:31 +02:00
App::new()
2019-03-26 04:29:00 +01:00
.wrap(redirect::CheckLogin)
.wrap(read_request_body::Logging)
.wrap(read_response_body::Logging)
2019-03-26 04:29:00 +01:00
.wrap(simple::SayHi)
2019-09-11 14:04:33 +02:00
.wrap_fn(|req, srv| {
println!("Hi from start. You requested: {}", req.path());
srv.call(req).map(|res| {
println!("Hi from response");
res
})
})
2019-03-10 19:19:50 -07:00
.service(web::resource("/login").to(|| {
2019-12-07 23:59:24 +06:00
async {
"You are on /login. Go to src/redirect.rs to change this behavior."
}
}))
.service(web::resource("/").to(|| {
async { "Hello, middleware! Check the console where the server is run." }
2019-03-10 19:19:50 -07:00
}))
2019-03-09 18:03:09 -08:00
})
2019-03-10 19:19:50 -07:00
.bind("127.0.0.1:8080")?
2019-12-25 20:48:33 +04:00
.run()
2019-12-07 23:59:24 +06:00
.await
2018-07-09 20:18:31 +02:00
}