Merge pull request #98 from openresearch/feature/no_rate_limit

introduce env variable DISABLE_RATE_LIMIT to disable rate limit
main
Cogent Apps 2023-04-12 02:37:25 -07:00 committed by GitHub
commit 019cd42be8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -67,12 +67,15 @@ export default class ChatServer {
this.app.use(express.json({ limit: '1mb' }));
this.app.use(compression());
const rateLimitWindowMs = process.env.RATE_LIMIT_WINDOW_MS ? parseInt(process.env.RATE_LIMIT_WINDOW_MS, 10) : 15 * 60 * 1000; // 15 minutes
const rateLimitMax = process.env.RATE_LIMIT_MAX ? parseInt(process.env.RATE_LIMIT_MAX, 10) : 100; // limit each IP to 100 requests per windowMs
const { default: rateLimit } = await import('express-rate-limit'); // esm
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // limit each IP to 100 requests per windowMs
windowMs: rateLimitWindowMs,
max: rateLimitMax,
});
this.app.use(limiter);
this.app.get('/chatapi/health', (req, res) => new HealthRequestHandler(this, req, res));