1.0.12 • Published 6 years ago

request-limit v1.0.12

Weekly downloads
4
License
ISC
Repository
github
Last release
6 years ago

通过redis缓存实现token对url的访问频率控制

token可为登录用户的ticket

安装

$ npm install request-limit

初始化

const limit = require('request-limit')
const urlMap = new Map()
urlMap.set('/api/user/getList.get', {limit: 2, interval: 20})
urlMap.set('/api/user/add.post', {limit: 2, interval: 2})
urlMap.set('/api/user/getOne.get', {limit: 2, interval: 2})

// 白名单
const whiteList = []
whiteList.push('/api/login.post')

limit.init(urlMap, {
    store: {
        host: '127.0.0.1',
        port: 6379
    },
    whiteList
})

其中,后面的参数为多少秒内访问多少次

如果不在urlMap里面设置,则使用默认配置24小时内访问1000次

在白名单中的url不受限制

使用

const limitRlt = await limit.checkLimit('token', 'url.post')
await limit.record('token', 'url.post')
1.0.12

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago