| const rateLimit = require('express-rate-limit');
|
|
|
| const createRateLimit = (windowMs, max, message) => {
|
| return rateLimit({
|
| windowMs,
|
| max,
|
| message: { error: message },
|
| standardHeaders: true,
|
| legacyHeaders: false,
|
| });
|
| };
|
|
|
|
|
| const generalRateLimit = createRateLimit(
|
| parseInt(process.env.RATE_LIMIT_WINDOW_MS) || 15 * 60 * 1000,
|
| parseInt(process.env.RATE_LIMIT_MAX_REQUESTS) || 100,
|
| 'Too many requests from this IP, please try again later.'
|
| );
|
|
|
|
|
| const authRateLimit = createRateLimit(
|
| 15 * 60 * 1000,
|
| 5,
|
| 'Too many authentication attempts, please try again later.'
|
| );
|
|
|
|
|
| const chatRateLimit = createRateLimit(
|
| 60 * 1000,
|
| 20,
|
| 'Too many messages sent, please slow down.'
|
| );
|
|
|
| module.exports = {
|
| general: generalRateLimit,
|
| auth: authRateLimit,
|
| chat: chatRateLimit
|
| }; |