import { RateLimiterRedis } from "rate-limiter-flexible" ; export const rateLimitMiddleware = ( rateLimiter , m = "Too many requests, slow down" ) => ( req , res , next ) => { rateLimiter . consume ( req . userId ) . then ( ( ) => { next ( ) ; } ) . catch ( ( ) => { res . status ( 429 ) . send ( m ) ; } ) ; } ;