ip-list.js 511 Bytes
'use strict';

const cache = global.yoho.cache.master;
const _ = require('lodash');
const config = global.yoho.config;
const logger = global.yoho.logger;

module.exports = (limiter, policy) => {
    const key = `${config.app}:limiter:${limiter.remoteIp}`;

    return cache.getAsync(key).then((result) => {
        logger.debug(key, result);

        if (result && _.isNumber(result)) {
            return Promise.resolve(policy);
        } else {
            return Promise.resolve(true);
        }
    });
};