From 51937a0d494594709cd80e65d7ac9334662b841b Mon Sep 17 00:00:00 2001 From: neon_arch Date: Sat, 2 Sep 2023 20:22:24 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20pass=20the=20new=20config?= =?UTF-8?q?=20option=20into=20the=20middleware=20config=20(#203)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index cd83d8a..be526d9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,7 @@ use crate::server::routes; use actix_cors::Cors; use actix_files as fs; +use actix_governor::{Governor, GovernorConfigBuilder}; use actix_web::{dev::Server, http::header, middleware::Logger, web, App, HttpServer}; use config::parser::Config; use handlebars::Handlebars; @@ -64,10 +65,17 @@ pub fn run(listener: TcpListener, config: Config) -> std::io::Result { ]); App::new() + .wrap(Logger::default()) // added logging middleware for logging. .app_data(handlebars_ref.clone()) .app_data(web::Data::new(config.clone())) .wrap(cors) - .wrap(Logger::default()) // added logging middleware for logging. + .wrap(Governor::new( + &GovernorConfigBuilder::default() + .per_second(config.rate_limter.time_limit as u64) + .burst_size(config.rate_limter.number_of_requests as u32) + .finish() + .unwrap(), + )) // Serve images and static files (css and js files). .service( fs::Files::new("/static", format!("{}/static", public_folder_path))