1
0
mirror of https://github.com/actix/examples synced 2024-11-27 16:02:57 +01:00

Add middleware example with wrap_fn

This commit is contained in:
Sven-Hendrik Haase 2019-09-11 14:04:33 +02:00
parent f232b6c684
commit 948054f1e4

View File

@ -1,4 +1,6 @@
use actix_web::{web, App, HttpServer};
use actix_service::Service;
use futures::future::Future;
#[allow(dead_code)]
mod redirect;
@ -13,6 +15,14 @@ fn main() -> std::io::Result<()> {
App::new()
.wrap(redirect::CheckLogin)
.wrap(simple::SayHi)
.wrap_fn(|req, srv| {
println!("Hi from start. You requested: {}", req.path());
srv.call(req).map(|res| {
println!("Hi from response");
res
})
})
.service(web::resource("/login").to(|| {
"You are on /login. Go to src/redirect.rs to change this behavior."
}))