introduce env variable DISABLE_RATE_LIMIT to disable rate limit

main
Philipp Schmid 2023-03-31 12:26:34 +02:00
parent 68147135f8
commit 415eb2194f
1 changed files with 8 additions and 6 deletions

View File

@ -67,6 +67,7 @@ export default class ChatServer {
this.app.use(express.json({ limit: '1mb' })); this.app.use(express.json({ limit: '1mb' }));
this.app.use(compression()); this.app.use(compression());
if (process.env.DISABLE_RATE_LIMIT !== 'true') {
const { default: rateLimit } = await import('express-rate-limit'); // esm const { default: rateLimit } = await import('express-rate-limit'); // esm
const limiter = rateLimit({ const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes windowMs: 15 * 60 * 1000, // 15 minutes
@ -74,6 +75,7 @@ export default class ChatServer {
}); });
this.app.use(limiter); this.app.use(limiter);
}
this.app.get('/chatapi/health', (req, res) => new HealthRequestHandler(this, req, res)); this.app.get('/chatapi/health', (req, res) => new HealthRequestHandler(this, req, res));
this.app.get('/chatapi/session', (req, res) => new SessionRequestHandler(this, req, res)); this.app.get('/chatapi/session', (req, res) => new SessionRequestHandler(this, req, res));