diff --git a/lib/cartodb/controllers/map.js b/lib/cartodb/controllers/map.js index e508ce75..abed83e8 100644 --- a/lib/cartodb/controllers/map.js +++ b/lib/cartodb/controllers/map.js @@ -57,31 +57,19 @@ MapController.prototype.register = function(app) { app.get( base_url_mapconfig, - cors(), - userMiddleware, - rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.ANONYMOUS), - this.composeCreateMapMiddleware() + this.composeCreateMapMiddleware(RATE_LIMIT_ENDPOINTS_GROUPS.ANONYMOUS) ); app.post( base_url_mapconfig, - cors(), - userMiddleware, - rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.ANONYMOUS), - this.composeCreateMapMiddleware() + this.composeCreateMapMiddleware(RATE_LIMIT_ENDPOINTS_GROUPS.ANONYMOUS) ); app.get( `${base_url_templated}/:template_id/jsonp`, - cors(), - userMiddleware, - rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED), - this.composeCreateMapMiddleware(useTemplate) + this.composeCreateMapMiddleware(RATE_LIMIT_ENDPOINTS_GROUPS.NAMED, useTemplate) ); app.post( `${base_url_templated}/:template_id`, - cors(), - userMiddleware, - rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED), - this.composeCreateMapMiddleware(useTemplate) + this.composeCreateMapMiddleware(RATE_LIMIT_ENDPOINTS_GROUPS.NAMED, useTemplate) ); app.options( app.base_url_mapconfig, @@ -89,7 +77,7 @@ MapController.prototype.register = function(app) { ); }; -MapController.prototype.composeCreateMapMiddleware = function (useTemplate = false) { +MapController.prototype.composeCreateMapMiddleware = function (endpoint = false, useTemplate = false) { const isTemplateInstantiation = useTemplate; const useTemplateHash = useTemplate; const includeQuery = !useTemplate; @@ -97,6 +85,9 @@ MapController.prototype.composeCreateMapMiddleware = function (useTemplate = fal const addContext = !useTemplate; return [ + cors(), + userMiddleware, + rateLimit(this.userLimitsApi, endpoint), allowQueryParams(['aggregation']), this.prepareContext, this.initProfiler(isTemplateInstantiation),