2024-09-11 22:51:39 +09:00
|
|
|
#![allow(dead_code, unused_variables)]
|
|
|
|
|
|
|
|
// <from-fn>
|
|
|
|
use actix_web::{
|
|
|
|
body::MessageBody,
|
|
|
|
dev::{ServiceRequest, ServiceResponse},
|
|
|
|
middleware::{from_fn, Next},
|
|
|
|
App, Error,
|
|
|
|
};
|
|
|
|
|
2024-10-15 21:02:25 +02:00
|
|
|
async fn my_middleware(
|
2024-09-11 22:51:39 +09:00
|
|
|
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() {
|
2024-10-15 21:02:25 +02:00
|
|
|
let app = App::new().wrap(from_fn(my_middleware));
|
2024-09-11 22:51:39 +09:00
|
|
|
}
|
|
|
|
// </from-fn>
|