@lidofinance/next-ip-rate-limit
v0.46.0
Published
IP rate limit for next server api requests
Downloads
1,320
Readme
@lidofinance/next-ip-rate-limit
IP rate limit for next server api requests.
Installation
yarn add @lidofinance/next-ip-rate-limit
.
Getting started
With Next.js API
import { ipRateLimit } from '@lidofinance/next-ip-rate-limit'
import { NextApiRequest, NextApiResponse } from 'next'
// env vars
const RATE_LIMIT = 60
const RATE_LIMIT_TIME_FRAME = 60 // 1 min
const someRequest = async (req, res) => {
ipRateLimit({
req,
res,
limit: RATE_LIMIT,
timeFrame: RATE_LIMIT_TIME_FRAME,
})
await fetch()
}
export default someRequest
With @lidofinance/next-api-wrapper
import { wrapRequest, API } from '@lidofinance/next-api-wrapper'
import { ipRateLimit, rateLimitWrapper } from '@lidofinance/next-ip-rate-limit'
const someRequest: API = async (req, res) => await fetch()
export const rateLimit = rateLimitWrapper({ rateLimit: RATE_LIMIT, rateLimitTimeFrame: RATE_LIMIT_TIME_FRAME })
export default wrapRequest([rateLimit, someWrapper])(someRequest)