NextNodeTemplate/backend/middleware/rateLimiter.js
2025-11-02 16:47:30 +03:00

32 lines
806 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Rate limiter для защиты от злоупотреблений
const rateLimit = require('express-rate-limit');
// Общий rate limiter
const generalLimiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 минут
max: 100, // максимум 100 запросов с одного IP за окно времени
message: {
success: false,
error: 'Too many requests from this IP, please try again later.',
},
standardHeaders: true,
legacyHeaders: false,
});
// Строгий rate limiter для API
const strictLimiter = rateLimit({
windowMs: 15 * 60 * 1000,
max: 20, // максимум 20 запросов
message: {
success: false,
error: 'Too many requests, please try again later.',
},
});
module.exports = {
generalLimiter,
strictLimiter,
};