diff --git a/lib/cartodb/controllers/layergroup.js b/lib/cartodb/controllers/layergroup.js index 0276527d..76647f53 100644 --- a/lib/cartodb/controllers/layergroup.js +++ b/lib/cartodb/controllers/layergroup.js @@ -5,6 +5,7 @@ var cors = require('../middleware/cors'); var userMiddleware = require('../middleware/user'); var allowQueryParams = require('../middleware/allow-query-params'); var vectorError = require('../middleware/vector-error'); +const { rateLimitMiddleware, RATE_LIMIT_ENDPOINTS_GROUPS } = require('../middleware/rate-limit'); var DataviewBackend = require('../backends/dataview'); var AnalysisStatusBackend = require('../backends/analysis-status'); @@ -26,8 +27,19 @@ var QueryTables = require('cartodb-query-tables'); * @param {AnalysisBackend} analysisBackend * @constructor */ -function LayergroupController(prepareContext, pgConnection, mapStore, tileBackend, previewBackend, attributesBackend, - surrogateKeysCache, userLimitsApi, layergroupAffectedTables, analysisBackend) { +function LayergroupController( + prepareContext, + pgConnection, + mapStore, + tileBackend, + previewBackend, + attributesBackend, + surrogateKeysCache, + userLimitsApi, + layergroupAffectedTables, + analysisBackend, + metadataBackend +) { this.pgConnection = pgConnection; this.mapStore = mapStore; this.tileBackend = tileBackend; @@ -41,6 +53,7 @@ function LayergroupController(prepareContext, pgConnection, mapStore, tileBacken this.analysisStatusBackend = new AnalysisStatusBackend(); this.prepareContext = prepareContext; + this.metadataBackend = metadataBackend; } module.exports = LayergroupController; @@ -50,6 +63,7 @@ LayergroupController.prototype.register = function(app) { app.base_url_mapconfig + '/:token/:z/:x/:y@:scale_factor?x.:format', cors(), userMiddleware, + rateLimitMiddleware(this.metadataBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ENDPOINT_8), this.prepareContext, this.tile.bind(this), vectorError() @@ -59,6 +73,7 @@ LayergroupController.prototype.register = function(app) { app.base_url_mapconfig + '/:token/:z/:x/:y.:format', cors(), userMiddleware, + rateLimitMiddleware(this.metadataBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ENDPOINT_8), this.prepareContext, this.tile.bind(this), vectorError() @@ -68,6 +83,7 @@ LayergroupController.prototype.register = function(app) { app.base_url_mapconfig + '/:token/:layer/:z/:x/:y.(:format)', cors(), userMiddleware, + rateLimitMiddleware(this.metadataBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ENDPOINT_8), validateLayerRouteMiddleware, this.prepareContext, this.layer.bind(this), @@ -78,6 +94,7 @@ LayergroupController.prototype.register = function(app) { app.base_url_mapconfig + '/:token/:layer/attributes/:fid', cors(), userMiddleware, + rateLimitMiddleware(this.metadataBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ENDPOINT_9), this.prepareContext, this.attributes.bind(this) ); @@ -86,6 +103,7 @@ LayergroupController.prototype.register = function(app) { app.base_url_mapconfig + '/static/center/:token/:z/:lat/:lng/:width/:height.:format', cors(), userMiddleware, + rateLimitMiddleware(this.metadataBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ENDPOINT_2), allowQueryParams(['layer']), this.prepareContext, this.center.bind(this) @@ -95,6 +113,7 @@ LayergroupController.prototype.register = function(app) { app.base_url_mapconfig + '/static/bbox/:token/:west,:south,:east,:north/:width/:height.:format', cors(), userMiddleware, + rateLimitMiddleware(this.metadataBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ENDPOINT_2), allowQueryParams(['layer']), this.prepareContext, this.bbox.bind(this) @@ -122,6 +141,7 @@ LayergroupController.prototype.register = function(app) { app.base_url_mapconfig + '/:token/dataview/:dataviewName', cors(), userMiddleware, + rateLimitMiddleware(this.metadataBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ENDPOINT_5), allowQueryParams(allowedDataviewQueryParams), this.prepareContext, this.dataview.bind(this) @@ -131,6 +151,7 @@ LayergroupController.prototype.register = function(app) { app.base_url_mapconfig + '/:token/:layer/widget/:dataviewName', cors(), userMiddleware, + rateLimitMiddleware(this.metadataBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ENDPOINT_5), allowQueryParams(allowedDataviewQueryParams), this.prepareContext, this.dataview.bind(this) @@ -140,6 +161,7 @@ LayergroupController.prototype.register = function(app) { app.base_url_mapconfig + '/:token/dataview/:dataviewName/search', cors(), userMiddleware, + rateLimitMiddleware(this.metadataBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ENDPOINT_6), allowQueryParams(allowedDataviewQueryParams), this.prepareContext, this.dataviewSearch.bind(this) @@ -149,6 +171,7 @@ LayergroupController.prototype.register = function(app) { app.base_url_mapconfig + '/:token/:layer/widget/:dataviewName/search', cors(), userMiddleware, + rateLimitMiddleware(this.metadataBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ENDPOINT_6), allowQueryParams(allowedDataviewQueryParams), this.prepareContext, this.dataviewSearch.bind(this) @@ -158,6 +181,7 @@ LayergroupController.prototype.register = function(app) { app.base_url_mapconfig + '/:token/analysis/node/:nodeId', cors(), userMiddleware, + rateLimitMiddleware(this.metadataBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ENDPOINT_7), this.prepareContext, this.analysisNodeStatus.bind(this) ); diff --git a/lib/cartodb/server.js b/lib/cartodb/server.js index 46ff7122..9e8669ce 100644 --- a/lib/cartodb/server.js +++ b/lib/cartodb/server.js @@ -233,7 +233,8 @@ module.exports = function(serverOptions) { surrogateKeysCache, userLimitsApi, layergroupAffectedTablesCache, - analysisBackend + analysisBackend, + metadataBackend ).register(app); new controller.Map( @@ -259,7 +260,7 @@ module.exports = function(serverOptions) { metadataBackend ).register(app); - new controller.NamedMapsAdmin(authApi, templateMaps).register(app); + new controller.NamedMapsAdmin(authApi, templateMaps, metadataBackend).register(app); new controller.Analyses(prepareContext).register(app);