1
0
mirror of https://github.com/actix/actix-website synced 2025-06-27 15:39:02 +02:00

Added documentation for from_fn and wrap in middleware page (#451)

* Added documentation for from_fn and wrap in middleware page

* Update docs/middleware.md

---------

Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
Ross
2024-09-11 22:51:39 +09:00
committed by GitHub
parent c3e64b5889
commit 50c3e75bc3
3 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,24 @@
#![allow(dead_code, unused_variables)]
// <from-fn>
use actix_web::{
body::MessageBody,
dev::{ServiceRequest, ServiceResponse},
middleware::{from_fn, Next},
App, Error,
};
async fn my_midleware(
req: ServiceRequest,
next: Next<impl MessageBody>,
) -> Result<ServiceResponse<impl MessageBody>, Error> {
// pre-processing
next.call(req).await
// post-processing
}
#[actix_web::main]
async fn main() {
let app = App::new().wrap(from_fn(my_midleware));
}
// </from-fn>

View File

@ -1,5 +1,6 @@
pub mod default_headers;
pub mod errorhandler;
pub mod from_fn;
pub mod logger;
pub mod user_sessions;
pub mod wrap_fn;