import { Middleware, Context } from 'koa' import * as smartLimiter from 'smart-limiter' import * as redis from './redis' import * as config from 'config' export const limiter: Middleware = smartLimiter.koav2({ redis, policy: config.APP.LIMITER.POLICY, duration: config.APP.LIMITER.DURATION, prefix: config.APP.LIMITER.PREFIX || 'TIS_LIMIT', getId: (ctx: Context) => { return ctx.get('x-real-ip') || ctx.get('x-forwarded-for') || ctx.ip } })