From 7b7408dab781fa5cbc7cb9ed6a95dcb4a3db4c7a Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Mon, 16 Dec 2013 17:17:55 +0100 Subject: [PATCH] Revert "Drop /map_metadata API entry point" This reverts commit b37b07a06a1dd3cf05d60f4aa613ab5c48b90700. This was too light of a decision... --- NEWS.md | 1 - README.md | 9 +++--- lib/cartodb/cartodb_windshaft.js | 20 ++++++++++++ lib/cartodb/server_options.js | 19 ++++++++++++ test/acceptance/server.js | 53 ++++++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index 485c0291..8f235148 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,6 @@ ------------------- * Update cartodb-redis dependency to "~0.2.0" -* Drop /map_metadata API entry point (#101) 1.5.2 -- 2013-12-05 ------------------- diff --git a/README.md b/README.md index b3412579..676236ef 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,16 @@ Windshaft-CartoDB [![Build Status](https://travis-ci.org/CartoDB/Windshaft-cartodb.png)](http://travis-ci.org/CartoDB/Windshaft-cartodb) -This is the CartoDB 2.0+ map tiler. It extends Windshaft with some extra +This is the CartoDB map tiler. It extends Windshaft with some extra functionality and custom filters for authentication -* reads dbname from hostname and cartodb redis for pretty tile urls +* reads dbname from subdomain and cartodb redis for pretty tile urls * configures windshaft to publish ``cartodb_id`` as the interactivity layer * gets the default geometry type from the cartodb redis store +* allows tiles to be styled individually * provides a link to varnish high speed cache * provides a infowindow endpoint for windshaft -* provides support for template signed maps +* provides a ``map_metadata`` endpoint for windshaft Requirements ------------ @@ -25,7 +26,7 @@ Requirements [for cache control] - CartoDB-SQL-API 1.0.0+ - - CartoDB 2.0.0+ + - CartoDB 0.9.5+ (for ``CDB_QueryTables``) - Varnish (https://www.varnish-cache.org) Configure diff --git a/lib/cartodb/cartodb_windshaft.js b/lib/cartodb/cartodb_windshaft.js index 0b730751..b436194a 100644 --- a/lib/cartodb/cartodb_windshaft.js +++ b/lib/cartodb/cartodb_windshaft.js @@ -55,6 +55,26 @@ var CartodbWindshaft = function(serverOptions) { }); + /** + * Helper to allow access to metadata to be used in embedded maps. + */ + ws.get(serverOptions.base_url + '/map_metadata', function(req, res){ + ws.doCORS(res); + Step( + function(){ + serverOptions.getMapMetadata(req, this); + }, + function(err, data){ + if (err){ + ws.sendError(res, {error: err.message}, 500, 'GET MAP_METADATA'); + //res.send(err.message, 500); + } else { + res.send({map_metadata: data}, 200); + } + } + ); + }); + /** * Helper API to allow per table tile cache (and sql cache) to be invalidated remotely. * TODO: Move? diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index ee6e5ec7..25456154 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -550,6 +550,25 @@ module.exports = function(){ ); }; + /** + * Little helper method to get map metadata and return to client + * @param req + * @param callback + */ + me.getMapMetadata = function(req, callback){ + var that = this; + + Step( + function(){ + that.req2params(req, this); + }, + function(err, data){ + if (err) callback(err, null); + else cartoData.getMapMetadata(data, callback); + } + ); + }; + /** * Helper to clear out tile cache on request * @param req diff --git a/test/acceptance/server.js b/test/acceptance/server.js index 403a17bf..33248fb5 100644 --- a/test/acceptance/server.js +++ b/test/acceptance/server.js @@ -1196,6 +1196,59 @@ suite('server', function() { }); }); + ///////////////////////////////////////////////////////////////////////////////// + // + // GET METADATA + // + ///////////////////////////////////////////////////////////////////////////////// + + test("does not provide metadata of private table to unauthenticated requests", function(done){ + assert.response(server, { + headers: {host: 'localhost'}, + url: '/tiles/test_table_private_1/map_metadata', + method: 'GET' + },{}, function(res) { + // FIXME: should be 401 instead + assert.equal(res.statusCode, 500, res.statusCode + ': ' + res.body); + done(); + }); + }); + + test("does provide metadata of private table to authenticated requests", function(done){ + assert.response(server, { + headers: {host: 'localhost'}, + url: '/tiles/test_table_private_1/map_metadata?map_key=1234', + method: 'GET' + },{}, function(res) { + assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body); + done(); + }); + }); + + test("does provide metadata of public table to unauthenticated requests", function(done){ + assert.response(server, { + headers: {host: 'localhost'}, + url: '/tiles/gadm4/map_metadata', + method: 'GET' + },{}, function(res) { + assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body); + // TODO: show metadata ? + done(); + }); + }); + + test("does provide metadata of public table to authenticated requests", function(done){ + assert.response(server, { + headers: {host: 'localhost'}, + url: '/tiles/gadm4/map_metadata?map_key=1234', + method: 'GET' + },{}, function(res) { + assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body); + // TODO: show metadata ? + done(); + }); + }); + ///////////////////////////////////////////////////////////////////////////////// // // DELETE CACHE