Spaces:
Runtime error
Runtime error
neon_arch
commited on
Commit
•
51937a0
1
Parent(s):
8cba040
✨ feat: pass the new config option into the middleware config (#203)
Browse files- src/lib.rs +9 -1
src/lib.rs
CHANGED
@@ -14,6 +14,7 @@ use crate::server::routes;
|
|
14 |
|
15 |
use actix_cors::Cors;
|
16 |
use actix_files as fs;
|
|
|
17 |
use actix_web::{dev::Server, http::header, middleware::Logger, web, App, HttpServer};
|
18 |
use config::parser::Config;
|
19 |
use handlebars::Handlebars;
|
@@ -64,10 +65,17 @@ pub fn run(listener: TcpListener, config: Config) -> std::io::Result<Server> {
|
|
64 |
]);
|
65 |
|
66 |
App::new()
|
|
|
67 |
.app_data(handlebars_ref.clone())
|
68 |
.app_data(web::Data::new(config.clone()))
|
69 |
.wrap(cors)
|
70 |
-
.wrap(
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
// Serve images and static files (css and js files).
|
72 |
.service(
|
73 |
fs::Files::new("/static", format!("{}/static", public_folder_path))
|
|
|
14 |
|
15 |
use actix_cors::Cors;
|
16 |
use actix_files as fs;
|
17 |
+
use actix_governor::{Governor, GovernorConfigBuilder};
|
18 |
use actix_web::{dev::Server, http::header, middleware::Logger, web, App, HttpServer};
|
19 |
use config::parser::Config;
|
20 |
use handlebars::Handlebars;
|
|
|
65 |
]);
|
66 |
|
67 |
App::new()
|
68 |
+
.wrap(Logger::default()) // added logging middleware for logging.
|
69 |
.app_data(handlebars_ref.clone())
|
70 |
.app_data(web::Data::new(config.clone()))
|
71 |
.wrap(cors)
|
72 |
+
.wrap(Governor::new(
|
73 |
+
&GovernorConfigBuilder::default()
|
74 |
+
.per_second(config.rate_limter.time_limit as u64)
|
75 |
+
.burst_size(config.rate_limter.number_of_requests as u32)
|
76 |
+
.finish()
|
77 |
+
.unwrap(),
|
78 |
+
))
|
79 |
// Serve images and static files (css and js files).
|
80 |
.service(
|
81 |
fs::Files::new("/static", format!("{}/static", public_folder_path))
|