Rate limiting + version fixes (#90)

* Rate limiting + version fixes

* Move patch to proper place

* More fixes

* Fix commit hash pin
This commit is contained in:
Geometrically
2020-10-25 13:51:07 -07:00
committed by GitHub
parent 1ff8c908b8
commit ef28459b61
7 changed files with 160 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
use crate::file_hosting::S3Host;
use actix_cors::Cors;
use actix_ratelimit::{MemoryStore, MemoryStoreActor, RateLimiter};
use actix_web::middleware::Logger;
use actix_web::{http, web, App, HttpServer};
use env_logger::Env;
@@ -205,6 +206,8 @@ async fn main() -> std::io::Result<()> {
.and_then(|s| serde_json::from_str::<Vec<String>>(&s).ok())
.unwrap_or_else(|| vec![String::from("http://localhost")]);
let store = MemoryStore::new();
info!("Starting Actix HTTP server!");
// Init App
@@ -222,6 +225,11 @@ async fn main() -> std::io::Result<()> {
.wrap(cors.finish())
.wrap(Logger::default())
.wrap(Logger::new("%a %{User-Agent}i"))
.wrap(
RateLimiter::new(MemoryStoreActor::from(store.clone()).start())
.with_interval(std::time::Duration::from_secs(60))
.with_max_requests(100),
)
.data(pool.clone())
.data(file_host.clone())
.data(indexing_queue.clone())