Skip to content

Commit

Permalink
Add a simple global rate limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
erikreppel authored Apr 22, 2024
1 parent 8794a9e commit 4bfc710
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use serde::Serialize;
use sqlx::SqlitePool;
use std::time::Duration;
use tokio::net::TcpListener;
use tower::buffer::BufferLayer;
use tower::limit::RateLimitLayer;
use tower::{BoxError, ServiceBuilder};

#[derive(Clone)]
Expand Down Expand Up @@ -44,6 +46,17 @@ pub fn router_with_defaults(config: &Config) -> Router<AppState> {
.route("/health", get(health))
.route("/list-all", get(list_all))
.route("/submit-premint", post(submit_premint))
.layer(
ServiceBuilder::new()
.layer(HandleErrorLayer::new(|error: BoxError| async move {
(
StatusCode::INTERNAL_SERVER_ERROR,
format!("Unhandled error: {:?}", error),
)
}))
.layer(BufferLayer::new(10000))
.layer(RateLimitLayer::new(60, Duration::from_secs(60))),
)
.layer(
ServiceBuilder::new()
.layer(HandleErrorLayer::new(|error: BoxError| async move {
Expand Down

0 comments on commit 4bfc710

Please sign in to comment.