diff --git a/lib/cartodb/controllers/named_maps.js b/lib/cartodb/controllers/named_maps.js index 0a839fb9..a6c0888c 100644 --- a/lib/cartodb/controllers/named_maps.js +++ b/lib/cartodb/controllers/named_maps.js @@ -9,6 +9,7 @@ var BaseController = require('./base'); var cors = require('../middleware/cors'); var userMiddleware = require('../middleware/user'); var allowQueryParams = require('../middleware/allow-query-params'); +const req2paramsMiddleware = require('../middleware/req2params-middleware'); function NamedMapsController(authApi, pgConnection, namedMapProviderCache, tileBackend, previewBackend, surrogateKeysCache, tablesExtentApi, metadataBackend) { @@ -20,6 +21,7 @@ function NamedMapsController(authApi, pgConnection, namedMapProviderCache, tileB this.surrogateKeysCache = surrogateKeysCache; this.tablesExtentApi = tablesExtentApi; this.metadataBackend = metadataBackend; + this.req2paramsMiddleware = req2paramsMiddleware(authApi, pgConnection); } util.inherits(NamedMapsController, BaseController); @@ -27,13 +29,21 @@ util.inherits(NamedMapsController, BaseController); module.exports = NamedMapsController; NamedMapsController.prototype.register = function(app) { - app.get(app.base_url_templated + - '/:template_id/:layer/:z/:x/:y.(:format)', cors(), userMiddleware, - this.tile.bind(this)); + app.get( + app.base_url_templated + '/:template_id/:layer/:z/:x/:y.(:format)', + cors(), + userMiddleware, + this.req2paramsMiddleware, + this.tile.bind(this) + ); - app.get(app.base_url_mapconfig + - '/static/named/:template_id/:width/:height.:format', cors(), userMiddleware, allowQueryParams(['layer']), - this.staticMap.bind(this)); + app.get( + app.base_url_mapconfig + '/static/named/:template_id/:width/:height.:format', + cors(), + userMiddleware, + allowQueryParams(['layer']), + this.staticMap.bind(this) + ); }; NamedMapsController.prototype.sendResponse = function(req, res, resource, headers, namedMapProvider) { @@ -81,11 +91,7 @@ NamedMapsController.prototype.tile = function(req, res, next) { var namedMapProvider; step( - function reqParams() { - self.req2params(req, res, this); - }, - function getNamedMapProvider(err) { - assert.ifError(err); + function getNamedMapProvider() { self.namedMapProviderCache.get( cdbUser, req.params.template_id,