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:
parent
f232b6c684
commit
948054f1e4
@ -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."
|
||||
}))
|
||||
|
Loading…
Reference in New Issue
Block a user