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