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

Merge pull request #169 from actix/wrap_fn-example

Add middleware example with wrap_fn
This commit is contained in:
Sven-Hendrik Haase 2019-09-11 16:34:27 +02:00 committed by GitHub
commit f026cb7041
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,6 @@
use actix_web::{web, App, HttpServer}; use actix_web::{web, App, HttpServer};
use actix_service::Service;
use futures::future::Future;
#[allow(dead_code)] #[allow(dead_code)]
mod redirect; mod redirect;
@ -13,6 +15,14 @@ fn main() -> std::io::Result<()> {
App::new() App::new()
.wrap(redirect::CheckLogin) .wrap(redirect::CheckLogin)
.wrap(simple::SayHi) .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(|| { .service(web::resource("/login").to(|| {
"You are on /login. Go to src/redirect.rs to change this behavior." "You are on /login. Go to src/redirect.rs to change this behavior."
})) }))