lib/routesHandler/lib/initializeRoutes.js
function (req, res, next) {
        var ip = IPAddressHelper.getClientIP(req)
            , route = req.miajs.route
            , key = ip + route.path + route.method;

        if (_.isEmpty(route.rateLimits)) {
            next();
            return;
        }

        RateLimiter.checkRateLimitsByKey(key, route.rateLimits).then(function (rateLimiterResult) {
            if (rateLimiterResult.remaining == -1) {
                _logInfo("Rate limit of " + rateLimiterResult.limit + "req/" + rateLimiterResult.timeInterval + "min requests exceeded " + route.requestmethod.toUpperCase() + " " + route.url + " for " + ip);
                res.header("X-Rate-Limit-Limit", rateLimiterResult.limit);
                res.header("X-Rate-Limit-Remaining", 0);
                res.header("X-Rate-Limit-Reset", rateLimiterResult.timeTillReset);
                next(new MiaError({
                    status: 429,
                    err: {
                        'code': 'RateLimitExceeded',
                        'msg': Translator('system', 'RateLimitExceeded')
                    }
                }));
            }
            else {
                res.header("X-Rate-Limit-Limit", rateLimiterResult.limit);
                res.header("X-Rate-Limit-Remaining", rateLimiterResult.remaining);
                res.header("X-Rate-Limit-Reset", rateLimiterResult.timeTillReset);
                next();
            }
        }).catch(function () {
            next();
        });
    }
function (req, res, next) {
        var ip = IPAddressHelper.getClientIP(req)
            , route = req.miajs.route
            , key = ip + route.path + route.method;

        if (_.isEmpty(route.rateLimits)) {
            next();
            return;
        }

        RateLimiter.checkRateLimitsByKey(key, route.rateLimits).then(function (rateLimiterResult) {
            if (rateLimiterResult.remaining == -1) {
                _logInfo("Rate limit of " + rateLimiterResult.limit + "req/" + rateLimiterResult.timeInterval + "min requests exceeded " + route.requestmethod.toUpperCase() + " " + route.url + " for " + ip);
                res.header("X-Rate-Limit-Limit", rateLimiterResult.limit);
                res.header("X-Rate-Limit-Remaining", 0);
                res.header("X-Rate-Limit-Reset", rateLimiterResult.timeTillReset);
                next(new MiaError({
                    status: 429,
                    err: {
                        'code': 'RateLimitExceeded',
                        'msg': Translator('system', 'RateLimitExceeded')
                    }
                }));
            }
            else {
                res.header("X-Rate-Limit-Limit", rateLimiterResult.limit);
                res.header("X-Rate-Limit-Remaining", rateLimiterResult.remaining);
                res.header("X-Rate-Limit-Reset", rateLimiterResult.timeTillReset);
                next();
            }
        }).catch(function () {
            next();
        });
    }
function ( req , res , next ) { var ip = IPAddressHelper . getClientIP ( req ) , route = req . miajs . route , key = ip + route . path + route . method ; if ( _ . isEmpty ( route . rateLimits ) ) { next ( ) ; return ; } RateLimiter . checkRateLimitsByKey ( key , route . rateLimits ) . then ( function ( rateLimiterResult ) { if ( rateLimiterResult . remaining == - 1 ) { _logInfo ( "Rate limit of " + rateLimiterResult . limit + "req/" + rateLimiterResult . timeInterval + "min requests exceeded " + route . requestmethod . toUpperCase ( ) + " " + route . url + " for " + ip ) ; res . header ( "X-Rate-Limit-Limit" , rateLimiterResult . limit ) ; res . header ( "X-Rate-Limit-Remaining" , 0 ) ; res . header ( "X-Rate-Limit-Reset" , rateLimiterResult . timeTillReset ) ; next ( new MiaError ( { status : 429 , err : { 'code' : 'RateLimitExceeded' , 'msg' : Translator ( 'system' , 'RateLimitExceeded' ) } } ) ) ; } else { res . header ( "X-Rate-Limit-Limit" , rateLimiterResult . limit ) ; res . header ( "X-Rate-Limit-Remaining" , rateLimiterResult . remaining ) ; res . header ( "X-Rate-Limit-Reset" , rateLimiterResult . timeTillReset ) ; next ( ) ; } } ) . catch ( function ( ) { next ( ) ; } ) ; }
Route for rate limits check
Route for rate limits check