我想为我的 API 创建一个速率限制层
使用 20 个 express-rate-limit
实例是个坏主意吗?
我可以预见的问题是性能下降、RAM 使用量增加
import * as rateLimit from 'express-rate-limit'
// import express, others...
const standard = {
hour: rateLimit({
windowMs: 60 * 60 * 1000, // 1 hour
max: 30, // limit each IP to 30 requests per windowMs
}),
day: rateLimit({
windowMs: 24 * 60 * 60 * 1000,
max: 100,
}),
week: rateLimit({
windowMs: 7 * 24 * 60 * 60 * 1000,
max: 200,
})
}
app.use(standard.hour)
app.use(standard.day)
app.use(standard.week)