mirror of
https://github.com/actix/actix-website
synced 2025-06-27 15:39:02 +02:00
Add bit about wrap_fn to middlewares page (#104)
This commit is contained in:
committed by
Nikolay Kim
parent
16b8702252
commit
a7c8116fcd
@ -2,6 +2,7 @@ pub mod default_headers;
|
||||
pub mod errorhandler;
|
||||
pub mod logger;
|
||||
pub mod user_sessions;
|
||||
pub mod wrap_fn;
|
||||
|
||||
// <simple>
|
||||
use actix_service::{Service, Transform};
|
||||
|
20
examples/middleware/src/wrap_fn.rs
Normal file
20
examples/middleware/src/wrap_fn.rs
Normal file
@ -0,0 +1,20 @@
|
||||
// <wrap-fn>
|
||||
use actix_service::Service;
|
||||
use actix_web::{web, App};
|
||||
use futures::future::Future;
|
||||
|
||||
fn main() {
|
||||
let app = App::new()
|
||||
.wrap_fn(|req, srv| {
|
||||
println!("Hi from start. You requested: {}", req.path());
|
||||
srv.call(req).map(|res| {
|
||||
println!("Hi from response");
|
||||
res
|
||||
})
|
||||
})
|
||||
.route(
|
||||
"/index.html",
|
||||
web::get().to(|| "Hello, middleware!"),
|
||||
);
|
||||
}
|
||||
// </wrap-fn>
|
Reference in New Issue
Block a user