From c8e8317ea44bab71730e19915a55e569d56cff16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Wed, 7 Mar 2018 15:20:47 +0100 Subject: [PATCH] Do not attach middleware to LayergroupController classs --- lib/cartodb/controllers/layergroup.js | 252 +++++++++++++------------- 1 file changed, 126 insertions(+), 126 deletions(-) diff --git a/lib/cartodb/controllers/layergroup.js b/lib/cartodb/controllers/layergroup.js index 9e0e7d28..bf2abeed 100644 --- a/lib/cartodb/controllers/layergroup.js +++ b/lib/cartodb/controllers/layergroup.js @@ -47,17 +47,17 @@ LayergroupController.prototype.register = function(app) { cors(), userMiddleware, this.prepareContext, - this.getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi), - this.tile(this.tileBackend), - this.setCacheControlHeader(), - this.setLastModifiedHeader(), - this.getAffectedTables(this.layergroupAffectedTables, this.pgConnection), - this.setCacheChannelHeader(), - this.setSurrogateKeyHeader(this.surrogateKeysCache), - this.incrementSuccessMetrics(global.statsClient), - this.sendResponse(), - this.incrementErrorMetrics(global.statsClient), - this.tileError(), + getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi), + tile(this.tileBackend), + setCacheControlHeader(), + setLastModifiedHeader(), + getAffectedTables(this.layergroupAffectedTables, this.pgConnection), + setCacheChannelHeader(), + setSurrogateKeyHeader(this.surrogateKeysCache), + incrementSuccessMetrics(global.statsClient), + sendResponse(), + incrementErrorMetrics(global.statsClient), + tileError(), vectorError() ); @@ -66,17 +66,17 @@ LayergroupController.prototype.register = function(app) { cors(), userMiddleware, this.prepareContext, - this.getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi), - this.tile(this.tileBackend), - this.setCacheControlHeader(), - this.setLastModifiedHeader(), - this.getAffectedTables(this.layergroupAffectedTables, this.pgConnection), - this.setCacheChannelHeader(), - this.setSurrogateKeyHeader(this.surrogateKeysCache), - this.incrementSuccessMetrics(global.statsClient), - this.sendResponse(), - this.incrementErrorMetrics(global.statsClient), - this.tileError(), + getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi), + tile(this.tileBackend), + setCacheControlHeader(), + setLastModifiedHeader(), + getAffectedTables(this.layergroupAffectedTables, this.pgConnection), + setCacheChannelHeader(), + setSurrogateKeyHeader(this.surrogateKeysCache), + incrementSuccessMetrics(global.statsClient), + sendResponse(), + incrementErrorMetrics(global.statsClient), + tileError(), vectorError() ); @@ -86,17 +86,17 @@ LayergroupController.prototype.register = function(app) { userMiddleware, validateLayerRoute(), this.prepareContext, - this.getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi), - this.layer(this.tileBackend), - this.setCacheControlHeader(), - this.setLastModifiedHeader(), - this.getAffectedTables(this.layergroupAffectedTables, this.pgConnection), - this.setCacheChannelHeader(), - this.setSurrogateKeyHeader(this.surrogateKeysCache), - this.incrementSuccessMetrics(global.statsClient), - this.sendResponse(), - this.incrementErrorMetrics(global.statsClient), - this.tileError(), + getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi), + layer(this.tileBackend), + setCacheControlHeader(), + setLastModifiedHeader(), + getAffectedTables(this.layergroupAffectedTables, this.pgConnection), + setCacheChannelHeader(), + setSurrogateKeyHeader(this.surrogateKeysCache), + incrementSuccessMetrics(global.statsClient), + sendResponse(), + incrementErrorMetrics(global.statsClient), + tileError(), vectorError() ); @@ -105,14 +105,14 @@ LayergroupController.prototype.register = function(app) { cors(), userMiddleware, this.prepareContext, - this.getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi), - this.attributes(this.attributesBackend), - this.setCacheControlHeader(), - this.setLastModifiedHeader(), - this.getAffectedTables(this.layergroupAffectedTables, this.pgConnection), - this.setCacheChannelHeader(), - this.setSurrogateKeyHeader(this.surrogateKeysCache), - this.sendResponse() + getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi), + attributes(this.attributesBackend), + setCacheControlHeader(), + setLastModifiedHeader(), + getAffectedTables(this.layergroupAffectedTables, this.pgConnection), + setCacheChannelHeader(), + setSurrogateKeyHeader(this.surrogateKeysCache), + sendResponse() ); const forcedFormat = 'png'; @@ -123,14 +123,14 @@ LayergroupController.prototype.register = function(app) { userMiddleware, allowQueryParams(['layer']), this.prepareContext, - this.getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi, forcedFormat), - this.center(this.previewBackend), - this.setCacheControlHeader(), - this.setLastModifiedHeader(), - this.getAffectedTables(this.layergroupAffectedTables, this.pgConnection), - this.setCacheChannelHeader(), - this.setSurrogateKeyHeader(this.surrogateKeysCache), - this.sendResponse() + getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi, forcedFormat), + center(this.previewBackend), + setCacheControlHeader(), + setLastModifiedHeader(), + getAffectedTables(this.layergroupAffectedTables, this.pgConnection), + setCacheChannelHeader(), + setSurrogateKeyHeader(this.surrogateKeysCache), + sendResponse() ); app.get( @@ -139,14 +139,14 @@ LayergroupController.prototype.register = function(app) { userMiddleware, allowQueryParams(['layer']), this.prepareContext, - this.getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi, forcedFormat), - this.bbox(this.previewBackend), - this.setCacheControlHeader(), - this.setLastModifiedHeader(), - this.getAffectedTables(this.layergroupAffectedTables, this.pgConnection), - this.setCacheChannelHeader(), - this.setSurrogateKeyHeader(this.surrogateKeysCache), - this.sendResponse() + getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi, forcedFormat), + bbox(this.previewBackend), + setCacheControlHeader(), + setLastModifiedHeader(), + getAffectedTables(this.layergroupAffectedTables, this.pgConnection), + setCacheChannelHeader(), + setSurrogateKeyHeader(this.surrogateKeysCache), + sendResponse() ); // Undocumented/non-supported API endpoint methods. @@ -173,14 +173,14 @@ LayergroupController.prototype.register = function(app) { userMiddleware, allowQueryParams(allowedDataviewQueryParams), this.prepareContext, - this.getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi), - this.getDataview(this.dataviewBackend), - this.setCacheControlHeader(), - this.setLastModifiedHeader(), - this.getAffectedTables(this.layergroupAffectedTables, this.pgConnection), - this.setCacheChannelHeader(), - this.setSurrogateKeyHeader(this.surrogateKeysCache), - this.sendResponse() + getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi), + getDataview(this.dataviewBackend), + setCacheControlHeader(), + setLastModifiedHeader(), + getAffectedTables(this.layergroupAffectedTables, this.pgConnection), + setCacheChannelHeader(), + setSurrogateKeyHeader(this.surrogateKeysCache), + sendResponse() ); app.get( @@ -189,14 +189,14 @@ LayergroupController.prototype.register = function(app) { userMiddleware, allowQueryParams(allowedDataviewQueryParams), this.prepareContext, - this.getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi), - this.getDataview(this.dataviewBackend), - this.setCacheControlHeader(), - this.setLastModifiedHeader(), - this.getAffectedTables(this.layergroupAffectedTables, this.pgConnection), - this.setCacheChannelHeader(), - this.setSurrogateKeyHeader(this.surrogateKeysCache), - this.sendResponse() + getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi), + getDataview(this.dataviewBackend), + setCacheControlHeader(), + setLastModifiedHeader(), + getAffectedTables(this.layergroupAffectedTables, this.pgConnection), + setCacheChannelHeader(), + setSurrogateKeyHeader(this.surrogateKeysCache), + sendResponse() ); app.get( @@ -205,14 +205,14 @@ LayergroupController.prototype.register = function(app) { userMiddleware, allowQueryParams(allowedDataviewQueryParams), this.prepareContext, - this.getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi), - this.dataviewSearch(this.dataviewBackend), - this.setCacheControlHeader(), - this.setLastModifiedHeader(), - this.getAffectedTables(this.layergroupAffectedTables, this.pgConnection), - this.setCacheChannelHeader(), - this.setSurrogateKeyHeader(this.surrogateKeysCache), - this.sendResponse() + getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi), + dataviewSearch(this.dataviewBackend), + setCacheControlHeader(), + setLastModifiedHeader(), + getAffectedTables(this.layergroupAffectedTables, this.pgConnection), + setCacheChannelHeader(), + setSurrogateKeyHeader(this.surrogateKeysCache), + sendResponse() ); app.get( @@ -221,14 +221,14 @@ LayergroupController.prototype.register = function(app) { userMiddleware, allowQueryParams(allowedDataviewQueryParams), this.prepareContext, - this.getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi), - this.dataviewSearch(this.dataviewBackend), - this.setCacheControlHeader(), - this.setLastModifiedHeader(), - this.getAffectedTables(this.layergroupAffectedTables, this.pgConnection), - this.setCacheChannelHeader(), - this.setSurrogateKeyHeader(this.surrogateKeysCache), - this.sendResponse() + getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi), + dataviewSearch(this.dataviewBackend), + setCacheControlHeader(), + setLastModifiedHeader(), + getAffectedTables(this.layergroupAffectedTables, this.pgConnection), + setCacheChannelHeader(), + setSurrogateKeyHeader(this.surrogateKeysCache), + sendResponse() ); app.get( @@ -236,8 +236,8 @@ LayergroupController.prototype.register = function(app) { cors(), userMiddleware, this.prepareContext, - this.analysisNodeStatus(this.analysisStatusBackend), - this.sendResponse() + analysisNodeStatus(this.analysisStatusBackend), + sendResponse() ); }; @@ -251,7 +251,7 @@ function validateLayerRoute () { }; } -LayergroupController.prototype.analysisNodeStatus = function (analysisStatusBackend) { +function analysisNodeStatus (analysisStatusBackend) { return function analysisNodeStatusMiddleware(req, res, next) { analysisStatusBackend.getNodeStatus(res.locals, (err, nodeStatus, stats = {}) => { req.profiler.add(stats); @@ -271,7 +271,7 @@ LayergroupController.prototype.analysisNodeStatus = function (analysisStatusBack next(); }); }; -}; +} function getRequestParams(locals) { const params = Object.assign({}, locals); @@ -282,7 +282,7 @@ function getRequestParams(locals) { return params; } -LayergroupController.prototype.getMapStoreMapConfigProvider = function (mapStore, userLimitsApi, forcedFormat = null) { +function getMapStoreMapConfigProvider (mapStore, userLimitsApi, forcedFormat = null) { return function getMapStoreMapConfigProviderMiddleware (req, res, next) { const { user } = res.locals; @@ -306,9 +306,9 @@ LayergroupController.prototype.getMapStoreMapConfigProvider = function (mapStore next(); }); }; -}; +} -LayergroupController.prototype.getDataview = function (dataviewBackend) { +function getDataview (dataviewBackend) { return function getDataviewMiddleware (req, res, next) { const { user, mapConfigProvider } = res.locals; const params = getRequestParams(res.locals); @@ -326,9 +326,9 @@ LayergroupController.prototype.getDataview = function (dataviewBackend) { next(); }); }; -}; +} -LayergroupController.prototype.dataviewSearch = function (dataviewBackend) { +function dataviewSearch (dataviewBackend) { return function dataviewSearchMiddleware (req, res, next) { const { user, dataviewName, mapConfigProvider } = res.locals; const params = getRequestParams(res.locals); @@ -346,9 +346,9 @@ LayergroupController.prototype.dataviewSearch = function (dataviewBackend) { next(); }); }; -}; +} -LayergroupController.prototype.attributes = function (attributesBackend) { +function attributes (attributesBackend) { return function attributesMiddleware (req, res, next) { req.profiler.start('windshaft.maplayer_attribute'); @@ -368,7 +368,7 @@ LayergroupController.prototype.attributes = function (attributesBackend) { next(); }); }; -}; +} function getStatusCode(tile, format){ return tile.length === 0 && format === 'mvt'? 204 : 200; @@ -394,7 +394,7 @@ function parseFormat (format = '') { return formatStat; } -LayergroupController.prototype.tile = function (tileBackend) { +function tile (tileBackend) { return function tileMiddleware (req, res, next) { req.profiler.start('windshaft.map_tile'); @@ -420,9 +420,9 @@ LayergroupController.prototype.tile = function (tileBackend) { next(); }); }; -}; +} -LayergroupController.prototype.layer = function (tileBackend) { +function layer (tileBackend) { return function layerMiddleware (req, res, next) { req.profiler.start('windshaft.maplayer_tile'); @@ -448,9 +448,9 @@ LayergroupController.prototype.layer = function (tileBackend) { next(); }); }; -}; +} -LayergroupController.prototype.center = function (previewBackend) { +function center (previewBackend) { return function centerMiddleware (req, res, next) { const width = +req.params.width; const height = +req.params.height; @@ -483,9 +483,9 @@ LayergroupController.prototype.center = function (previewBackend) { next(); }); }; -}; +} -LayergroupController.prototype.bbox = function (previewBackend) { +function bbox (previewBackend) { return function bboxMiddleware (req, res, next) { const width = +req.params.width; const height = +req.params.height; @@ -518,9 +518,9 @@ LayergroupController.prototype.bbox = function (previewBackend) { next(); }); }; -}; +} -LayergroupController.prototype.setLastModifiedHeader = function () { +function setLastModifiedHeader () { return function setLastModifiedHeaderMiddleware (req, res, next) { let { cache_buster: cacheBuster } = res.locals; @@ -532,17 +532,17 @@ LayergroupController.prototype.setLastModifiedHeader = function () { next(); }; -}; +} -LayergroupController.prototype.setCacheControlHeader = function () { +function setCacheControlHeader () { return function setCacheControlHeaderMiddleware (req, res, next) { res.set('Cache-Control', 'public,max-age=31536000'); next(); }; -}; +} -LayergroupController.prototype.getAffectedTables = function (layergroupAffectedTables, pgConnection) { +function getAffectedTables (layergroupAffectedTables, pgConnection) { return function getAffectedTablesMiddleware (req, res, next) { const { user, dbname, token, mapconfig } = res.locals; @@ -583,9 +583,9 @@ LayergroupController.prototype.getAffectedTables = function (layergroupAffectedT }); }); }; -}; +} -LayergroupController.prototype.setCacheChannelHeader = function () { +function setCacheChannelHeader () { return function setCacheChannelHeaderMiddleware (req, res, next) { const { affectedTables } = res.locals; @@ -595,9 +595,9 @@ LayergroupController.prototype.setCacheChannelHeader = function () { next(); }; -}; +} -LayergroupController.prototype.setSurrogateKeyHeader = function (surrogateKeysCache) { +function setSurrogateKeyHeader (surrogateKeysCache) { return function setSurrogateKeyHeaderMiddleware (req, res, next) { const { affectedTables } = res.locals; @@ -607,9 +607,9 @@ LayergroupController.prototype.setSurrogateKeyHeader = function (surrogateKeysCa next(); }; -}; +} -LayergroupController.prototype.incrementSuccessMetrics = function (statsClient) { +function incrementSuccessMetrics (statsClient) { return function incrementSuccessMetricsMiddleware (req, res, next) { const formatStat = parseFormat(req.params.format); @@ -618,9 +618,9 @@ LayergroupController.prototype.incrementSuccessMetrics = function (statsClient) next(); }; -}; +} -LayergroupController.prototype.sendResponse = function () { +function sendResponse () { return function sendResponseMiddleware (req, res) { req.profiler.done('res'); @@ -636,9 +636,9 @@ LayergroupController.prototype.sendResponse = function () { res.send(res.body); } }; -}; +} -LayergroupController.prototype.incrementErrorMetrics = function (statsClient) { +function incrementErrorMetrics (statsClient) { return function incrementErrorMetricsMiddleware (err, req, res, next) { const formatStat = parseFormat(req.params.format); @@ -649,7 +649,7 @@ LayergroupController.prototype.incrementErrorMetrics = function (statsClient) { }; }; -LayergroupController.prototype.tileError = function () { +function tileError () { return function tileErrorMiddleware (err, req, res, next) { // See https://github.com/Vizzuality/Windshaft-cartodb/issues/68 let errMsg = err.message ? ( '' + err.message ) : ( '' + err ); @@ -666,4 +666,4 @@ LayergroupController.prototype.tileError = function () { next(err); }; -}; +}