lib/routesHandler/lib/initializeRoutes.js
function (routeConfig, methodValue) {
        var rateLimits = [];
        var environment = Shared.config("environment");
        var globalRateLimit = environment.rateLimit;
        if (globalRateLimit) {
            if (globalRateLimit.interval && _.isNumber(globalRateLimit.interval) && parseInt(globalRateLimit.interval) > 0 && globalRateLimit.maxRequests && _.isNumber(globalRateLimit.maxRequests) && parseInt(globalRateLimit.maxRequests) > 0) {
                rateLimits.push(globalRateLimit);
            }
            else {
                throw new Error('Global rate limit config invalid' + ". Provide parameters 'interval' and 'maxRequests' with Int value");
            }
        }
        if (routeConfig && routeConfig.rateLimit) {
            if (routeConfig.rateLimit.interval && _.isNumber(routeConfig.rateLimit.interval) && parseInt(routeConfig.rateLimit.interval) > 0 && routeConfig.rateLimit.maxRequests && _.isNumber(routeConfig.rateLimit.maxRequests) && parseInt(routeConfig.rateLimit.maxRequests) > 0) {
                rateLimits.push(routeConfig.rateLimit);
            }
            else {
                throw new Error('Rate limit config invalid for route file ' + routeConfig.prefix + ". Provide parameters 'interval' and 'maxRequests' with Int value");
            }
        }
        if (methodValue && methodValue.rateLimit) {
            if (methodValue.rateLimit.interval && _.isNumber(methodValue.rateLimit.interval) && parseInt(methodValue.rateLimit.interval) > 0 && methodValue.rateLimit.maxRequests && _.isNumber(methodValue.rateLimit.maxRequests) && parseInt(methodValue.rateLimit.maxRequests) > 0) {
                rateLimits.push(methodValue.rateLimit);
            }
            else {
                throw new Error('Rate limit config invalid for route ' + methodValue.identity + ' in route file ' + routeConfig.prefix + ". Provide parameters 'interval' and 'maxRequests' with Int value");
            }
        }

        if (!_.isEmpty(rateLimits) && !Shared.memcached()) {
            throw new Error("Rate limits set but memcached not configured. Provide settings for memcached in environment config file");
        }

        return rateLimits;
    }
function (routeConfig, methodValue) {
        var rateLimits = [];
        var environment = Shared.config("environment");
        var globalRateLimit = environment.rateLimit;
        if (globalRateLimit) {
            if (globalRateLimit.interval && _.isNumber(globalRateLimit.interval) && parseInt(globalRateLimit.interval) > 0 && globalRateLimit.maxRequests && _.isNumber(globalRateLimit.maxRequests) && parseInt(globalRateLimit.maxRequests) > 0) {
                rateLimits.push(globalRateLimit);
            }
            else {
                throw new Error('Global rate limit config invalid' + ". Provide parameters 'interval' and 'maxRequests' with Int value");
            }
        }
        if (routeConfig && routeConfig.rateLimit) {
            if (routeConfig.rateLimit.interval && _.isNumber(routeConfig.rateLimit.interval) && parseInt(routeConfig.rateLimit.interval) > 0 && routeConfig.rateLimit.maxRequests && _.isNumber(routeConfig.rateLimit.maxRequests) && parseInt(routeConfig.rateLimit.maxRequests) > 0) {
                rateLimits.push(routeConfig.rateLimit);
            }
            else {
                throw new Error('Rate limit config invalid for route file ' + routeConfig.prefix + ". Provide parameters 'interval' and 'maxRequests' with Int value");
            }
        }
        if (methodValue && methodValue.rateLimit) {
            if (methodValue.rateLimit.interval && _.isNumber(methodValue.rateLimit.interval) && parseInt(methodValue.rateLimit.interval) > 0 && methodValue.rateLimit.maxRequests && _.isNumber(methodValue.rateLimit.maxRequests) && parseInt(methodValue.rateLimit.maxRequests) > 0) {
                rateLimits.push(methodValue.rateLimit);
            }
            else {
                throw new Error('Rate limit config invalid for route ' + methodValue.identity + ' in route file ' + routeConfig.prefix + ". Provide parameters 'interval' and 'maxRequests' with Int value");
            }
        }

        if (!_.isEmpty(rateLimits) && !Shared.memcached()) {
            throw new Error("Rate limits set but memcached not configured. Provide settings for memcached in environment config file");
        }

        return rateLimits;
    }
function ( routeConfig , methodValue ) { var rateLimits = [ ] ; var environment = Shared . config ( "environment" ) ; var globalRateLimit = environment . rateLimit ; if ( globalRateLimit ) { if ( globalRateLimit . interval && _ . isNumber ( globalRateLimit . interval ) && parseInt ( globalRateLimit . interval ) > 0 && globalRateLimit . maxRequests && _ . isNumber ( globalRateLimit . maxRequests ) && parseInt ( globalRateLimit . maxRequests ) > 0 ) { rateLimits . push ( globalRateLimit ) ; } else { throw new Error ( 'Global rate limit config invalid' + ". Provide parameters 'interval' and 'maxRequests' with Int value" ) ; } } if ( routeConfig && routeConfig . rateLimit ) { if ( routeConfig . rateLimit . interval && _ . isNumber ( routeConfig . rateLimit . interval ) && parseInt ( routeConfig . rateLimit . interval ) > 0 && routeConfig . rateLimit . maxRequests && _ . isNumber ( routeConfig . rateLimit . maxRequests ) && parseInt ( routeConfig . rateLimit . maxRequests ) > 0 ) { rateLimits . push ( routeConfig . rateLimit ) ; } else { throw new Error ( 'Rate limit config invalid for route file ' + routeConfig . prefix + ". Provide parameters 'interval' and 'maxRequests' with Int value" ) ; } } if ( methodValue && methodValue . rateLimit ) { if ( methodValue . rateLimit . interval && _ . isNumber ( methodValue . rateLimit . interval ) && parseInt ( methodValue . rateLimit . interval ) > 0 && methodValue . rateLimit . maxRequests && _ . isNumber ( methodValue . rateLimit . maxRequests ) && parseInt ( methodValue . rateLimit . maxRequests ) > 0 ) { rateLimits . push ( methodValue . rateLimit ) ; } else { throw new Error ( 'Rate limit config invalid for route ' + methodValue . identity + ' in route file ' + routeConfig . prefix + ". Provide parameters 'interval' and 'maxRequests' with Int value" ) ; } } if ( ! _ . isEmpty ( rateLimits ) && ! Shared . memcached ( ) ) { throw new Error ( "Rate limits set but memcached not configured. Provide settings for memcached in environment config file" ) ; } return rateLimits ; }
Validate rate limits settings
Validate rate limits settings