Skip to content

Commit

Permalink
Feature: Rate limiting chat feature
Browse files Browse the repository at this point in the history
Changes:
- 20 requests an hour for chat endpoint
  • Loading branch information
DennisJensen95 committed Oct 24, 2023
1 parent fad4cde commit 0295bbd
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 3 deletions.
102 changes: 102 additions & 0 deletions apps/backend/backend-server/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/backend/backend-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"

[dependencies]
actix-files = "0.6.2"
actix-governor = "0.5.0"
actix-session = "0.7.2"
actix-web = "4.3.1"
anyhow = "1.0.72"
Expand Down
16 changes: 13 additions & 3 deletions apps/backend/backend-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use actix_files as fs;
use actix_governor::{Governor, GovernorConfigBuilder};
use actix_web::{error, web, App, Error, HttpRequest, HttpResponse, HttpServer, Responder, Result};
use futures::StreamExt;
use log::info;
use serde::{Deserialize, Serialize};

use std::time::Duration;
// Application imports
mod chat;
mod search;
Expand All @@ -23,10 +24,19 @@ async fn main() -> std::io::Result<()> {

info!("Starting the server...");

HttpServer::new(|| {
let governor_conf = GovernorConfigBuilder::default()
.period(Duration::from_secs(3600))
.burst_size(20)
.finish()
.unwrap();

HttpServer::new(move || {
App::new()
.route(
"/chat",
web::post().to(chat).wrap(Governor::new(&governor_conf)),
)
.route("/health", web::get().to(health))
.route("/chat", web::post().to(chat))
.service(
fs::Files::new("/", "./digital-craftsman")
.index_file("index.html")
Expand Down

0 comments on commit 0295bbd

Please sign in to comment.