File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 2828 "cors" : " ^2.8.5" ,
2929 "dotenv" : " ^16.4.7" ,
3030 "express" : " ^4.21.2" ,
31+ "express-rate-limit" : " ^7.5.0" ,
3132 "ffmpeg-static" : " ^5.2.0" ,
3233 "hashids" : " ^2.3.0" ,
3334 "morgan" : " ^1.10.0" ,
4546 "@types/cors" : " ^2.8.17" ,
4647 "@types/dotenv" : " ^8.2.3" ,
4748 "@types/express" : " 4.17.21" ,
49+ "@types/express-rate-limit" : " ^6.0.2" ,
4850 "@types/ffmpeg-static" : " ^2.0.0" ,
4951 "@types/hashids" : " ^1.0.30" ,
5052 "@types/jest" : " ^29.5.14" ,
Original file line number Diff line number Diff line change 11import express , { Request , Response } from 'express' ;
22import { promises as fs } from 'fs' ;
33import path from 'path' ;
4+ import rateLimit from 'express-rate-limit' ;
45
56import logger from '../logger.js' ;
67import process from 'process' ;
78
89const router = express . Router ( ) ;
910
11+ // Rate limiting middleware for logs routes
12+ const logsRateLimit = rateLimit ( {
13+ windowMs : 15 * 60 * 1000 , // 15 minutes
14+ max : 20 , // Limit each IP to 20 requests per windowMs
15+ message : {
16+ error : 'Too many log requests from this IP, please try again later.'
17+ } ,
18+ standardHeaders : true , // Return rate limit info in the `RateLimit-*` headers
19+ legacyHeaders : false , // Disable the `X-RateLimit-*` headers
20+ } ) ;
21+
22+ // Apply rate limiting to all routes in this router
23+ router . use ( logsRateLimit ) ;
24+
1025// Get list of available log files
1126router . get ( '/' , async ( _req : Request , res : Response ) => {
1227 // [ ] add an auth mechanism. Below fcn is based on
You can’t perform that action at this time.
0 commit comments