node.js - 此包中的 ratelimit 装饰器 loopback4-ratelimiter 不起作用
问题描述
此包loopback4-ratelimiter中的ratelimit 装饰器不起作用(没有错误)。使用序列它工作正常,但我想限制特定 api 的速率。我已将其从序列中删除。
我正在使用一个名为“redis”的新创建的 Redis 数据源。当通过序列实现速率限制时,我可以看到在 redis 中创建了键。
下面是我的实现:
控制器.ts
@ratelimit(true, {
max: 4
})
@post('/add_user', {
responses: {
'200': {
description: 'Add User',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
is_success: {
type: 'boolean',
},
},
},
},
},
},
},
})
async addUser(): Promise<{is_success: boolean}> {
return {is_success: true}
}
应用程序.ts
this.component(RateLimiterComponent);
this.bind(RateLimitSecurityBindings.CONFIG).to({
name: 'redis',
max: 10,
windowMs: 900000, // #9
message: 'Too many requests, please try again later.'
});
包.json
"engines": {
"node": ">=10.16"
},
"dependencies": {
"@loopback/authentication": "^7.0.1",
"@loopback/authentication-jwt": "^0.7.1",
"@loopback/authorization": "0.7.1",
"@loopback/boot": "^3.0.1",
"@loopback/core": "^2.10.1",
"@loopback/cron": "^0.4.1",
"@loopback/repository": "^3.0.1",
"@loopback/rest": "^7.0.1",
"@loopback/rest-explorer": "^3.0.1",
"@loopback/service-proxy": "^3.0.1",
"loopback-connector-kv-redis": "3.0.0",
"loopback4-ratelimiter": "^2.2.0",
}
"devDependencies": {
"@loopback/build": "^6.2.4",
"@types/node": "^10.17.35",
"typescript": "~4.0.2"
}
GitHub问题 - https://github.com/sourcefuse/loopback4-ratelimiter/issues/19#issue-890804261
解决方案
推荐阅读
- python - 从文件中读取参数然后传递给python3中的子程序的包装函数
- javascript - 是否有稳定的设备互联网地址?
- angular - 为什么我会收到这样的错误?错误 TS2564:
- javascript - 与 Promise.all 并行加载和处理文件
- python - EventGrid 触发的 Python Azure 函数“ClientOtherError”和“AuthorizationError”,如何排查?
- spring-boot - @Embeddable Composite Key 不会在 Spring Data JPA 中引发完整性异常
- javascript - 使用 openweathermap api 时无法访问某些对象属性
- selenium - InvalidSelectorException 和 NoSuchElementException 和定位项之间的区别
- android - 在 recyclerview 适配器中自动播放音乐和视频
- r - 子集数据框中的特定行,但保留观察结果