aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-01-04 17:54:49 -0800
committerFuwn <[email protected]>2022-01-04 17:54:49 -0800
commitfb6cd8dacf0a022c8b7a1bf1eb77e3f8b909c4ba (patch)
tree0e6614c2f256d04844c484e4523ae8d53dd9f0c1 /src
parentchore(Cargo.toml): tidy up (diff)
downloadapi-fb6cd8dacf0a022c8b7a1bf1eb77e3f8b909c4ba.tar.xz
api-fb6cd8dacf0a022c8b7a1bf1eb77e3f8b909c4ba.zip
feat(main.rs): ratelimit (100 requests/minute)
Diffstat (limited to 'src')
-rw-r--r--src/main.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 6f07c84..cd689ed 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -15,9 +15,18 @@ pub mod utils;
async fn main() -> std::io::Result<()> {
dotenv::dotenv().ok();
- actix_web::HttpServer::new(|| {
+ let store = actix_ratelimit::MemoryStore::new();
+
+ actix_web::HttpServer::new(move || {
actix_web::App::new()
.wrap(actix_cors::Cors::default().allow_any_origin())
+ .wrap(
+ actix_ratelimit::RateLimiter::new(
+ actix_ratelimit::MemoryStoreActor::from(store.clone()).start(),
+ )
+ .with_interval(std::time::Duration::from_secs(60))
+ .with_max_requests(100),
+ )
.service(routes::index)
.service(
actix_web::web::scope("/api/v1")