import { NextApiMiddleware } from '@api/shared/shared.types' ; import rateLimit from 'express-rate-limit' ; import runMiddleware from './run-middleware' ; import { TooManyRequestsError } from '@api/error-handling/http-errors' ; const limiter = rateLimit ( { windowMs : 60 * 1000 , max : 100 , handler : ( ) => { throw new TooManyRequestsError ( ) ; } , } ) ; const rateLimiter = ( fn ) => async ( req , res ) => { await runMiddleware ( req , res , limiter ) ; return fn ( req , res ) ; } ; export default rateLimiter ;