Skip to content

Commit

Permalink
introduce env variable DISABLE_RATE_LIMIT to disable rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidp committed Mar 31, 2023
1 parent 6814713 commit 415eb21
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ export default class ChatServer {
this.app.use(express.json({ limit: '1mb' }));
this.app.use(compression());

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
});
if (process.env.DISABLE_RATE_LIMIT !== 'true') {
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
});

this.app.use(limiter);
this.app.use(limiter);
}

this.app.get('/chatapi/health', (req, res) => new HealthRequestHandler(this, req, res));
this.app.get('/chatapi/session', (req, res) => new SessionRequestHandler(this, req, res));
Expand Down

0 comments on commit 415eb21

Please sign in to comment.