Skip to content

Commit

Permalink
feat: rate limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseAlbDR committed Apr 17, 2024
1 parent 789ca95 commit 5e778a9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
15 changes: 15 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"env-var": "^7.4.1",
"express": "^4.18.2",
"express-async-errors": "^3.1.1",
"express-rate-limit": "^7.2.0",
"http-status-codes": "^2.3.0",
"jsonwebtoken": "^9.0.2",
"langchain": "^0.1.21",
Expand Down
11 changes: 10 additions & 1 deletion src/presentation/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@ import { ChatbotService } from './chatbot/service';
import { envs } from '../config/envs';
import { ChatbotController } from './chatbot/controller';
import { ChatbotRoutes } from './chatbot/routes';
import rateLimiter from 'express-rate-limit';

export class AppRoutes {
static get routes(): Router {
const router = Router();

router.use('/api/chat', ChatbotRoutes.routes);
const apiLimiter = rateLimiter({
windowMs: 60 * 1000,
max: 100,
message: {
msg: 'Máximo de peticiones alcanzado, reintentalo tras 1 minuto',
},
});

router.use('/api/chat', apiLimiter, ChatbotRoutes.routes);

return router;
}
Expand Down

0 comments on commit 5e778a9

Please sign in to comment.