From 9018e3976263fc7fb4950d93a835fdf46b10862f Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 5 Feb 2014 15:14:47 +0100 Subject: [PATCH] Make endpoints configurable Closes #127 Uses /api/v1/maps* in the production and staging example configs, keeps /maps* for development and test (they are examples...) --- NEWS.md | 3 ++- config/environments/development.js.example | 16 ++++++++++++++++ config/environments/production.js.example | 16 ++++++++++++++++ config/environments/staging.js.example | 16 ++++++++++++++++ config/environments/test.js.example | 16 ++++++++++++++++ lib/cartodb/cartodb_windshaft.js | 7 ++++--- lib/cartodb/server_options.js | 13 ++++++++++--- 7 files changed, 80 insertions(+), 7 deletions(-) diff --git a/NEWS.md b/NEWS.md index f1e64ad5..a7831334 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,7 +5,8 @@ New features: * Add support for torque tiles (#112) * Add attributes service (#118) - * Implement Unified Map API (#127) + * Implement Unified Map API (#126) + * Make endpoints configurable (#127) Enhancements: diff --git a/config/environments/development.js.example b/config/environments/development.js.example index fae9482e..234eea84 100644 --- a/config/environments/development.js.example +++ b/config/environments/development.js.example @@ -5,6 +5,22 @@ var config = { // Regular expression pattern to extract username // from hostname. Must have a single grabbing block. ,user_from_host: '^(.*)\\.localhost' + + // Base URLs for the APIs + // + // See http://github.com/CartoDB/Windshaft-cartodb/wiki/Unified-Map-API + // + // Base url for the Templated Maps API + // "/maps/named" is the new API, + // "/tiles/template" is for compatibility with versions up to 1.6.x + ,base_url_templated: '(?:/maps/named|/tiles/template)' + // Base url for the Detached Maps API + // "maps" is the the new API, + // "tiles/layergroup" is for compatibility with versions up to 1.6.x + ,base_url_detached: '(?:/maps|/tiles/layergroup)' + // Base url for the Inline Maps and Table Maps API + ,base_url_legacy: '/tiles/:table' + // Maximum number of connections for one process // 128 is a good value with a limit of 1024 open file descriptors ,maxConnections:128 diff --git a/config/environments/production.js.example b/config/environments/production.js.example index a636d697..6c612f81 100644 --- a/config/environments/production.js.example +++ b/config/environments/production.js.example @@ -5,6 +5,22 @@ var config = { // Regular expression pattern to extract username // from hostname. Must have a single grabbing block. ,user_from_host: '^(.*)\\.cartodb\\.com$' + + // Base URLs for the APIs + // + // See http://github.com/CartoDB/Windshaft-cartodb/wiki/Unified-Map-API + // + // Base url for the Templated Maps API + // "/maps/named" is the new API, + // "/tiles/template" is for compatibility with versions up to 1.6.x + ,base_url_templated: '(?:/maps/named|/tiles/template)' + // Base url for the Detached Maps API + // "maps" is the the new API, + // "tiles/layergroup" is for compatibility with versions up to 1.6.x + ,base_url_detached: '(?:/maps|/tiles/layergroup)' + // Base url for the Inline Maps and Table Maps API + ,base_url_legacy: '/tiles/:table' + // Maximum number of connections for one process // 128 is a good value with a limit of 1024 open file descriptors ,maxConnections:128 diff --git a/config/environments/staging.js.example b/config/environments/staging.js.example index 97ede9a5..6b603c4c 100644 --- a/config/environments/staging.js.example +++ b/config/environments/staging.js.example @@ -5,6 +5,22 @@ var config = { // Regular expression pattern to extract username // from hostname. Must have a single grabbing block. ,user_from_host: '^(.*)\\.cartodb\\.com$' + + // Base URLs for the APIs + // + // See http://github.com/CartoDB/Windshaft-cartodb/wiki/Unified-Map-API + // + // Base url for the Templated Maps API + // "/api/v1/maps/named" is the new API, + // "/tiles/template" is for compatibility with versions up to 1.6.x + ,base_url_templated: '(?:/api/v1/maps/named|/tiles/template)' + // Base url for the Detached Maps API + // "/api/v1/maps" is the the new API, + // "/tiles/layergroup" is for compatibility with versions up to 1.6.x + ,base_url_detached: '(?:/api/v1/maps|/tiles/layergroup)' + // Base url for the Inline Maps and Table Maps API + ,base_url_legacy: '/tiles/:table' + // Maximum number of connections for one process // 128 is a good value with a limit of 1024 open file descriptors ,maxConnections:128 diff --git a/config/environments/test.js.example b/config/environments/test.js.example index c523ba7d..e2da484e 100644 --- a/config/environments/test.js.example +++ b/config/environments/test.js.example @@ -5,6 +5,22 @@ var config = { // Regular expression pattern to extract username // from hostname. Must have a single grabbing block. ,user_from_host: '(.*)' + + // Base URLs for the APIs + // + // See https://github.com/CartoDB/Windshaft-cartodb/wiki/Unified-Map-API + // + // Base url for the Templated Maps API + // "/maps/named" is the new API, + // "/tiles/template" is for compatibility with versions up to 1.6.x + ,base_url_templated: '(?:/maps/named|/tiles/template)' + // Base url for the Detached Maps API + // "maps" is the the new API, + // "tiles/layergroup" is for compatibility with versions up to 1.6.x + ,base_url_detached: '(?:/maps|/tiles/layergroup)' + // Base url for the Inline Maps and Table Maps API + ,base_url_legacy: '/tiles/:table' + // Maximum number of connections for one process // 128 is a good value with a limit of 1024 open file descriptors ,maxConnections:128 diff --git a/lib/cartodb/cartodb_windshaft.js b/lib/cartodb/cartodb_windshaft.js index 0af28351..92750536 100644 --- a/lib/cartodb/cartodb_windshaft.js +++ b/lib/cartodb/cartodb_windshaft.js @@ -127,10 +127,11 @@ var CartodbWindshaft = function(serverOptions) { return serverOptions.userByReq(req); } + // This is for Templated maps + // // "named" is the official, "template" is for backward compatibility up to 1.6.x - //var template_baseurl = serverOptions.base_url_notable + '/(template|named)'; - var template_baseurl = '/tiles/template'; - var template_baseurl = '(?:/maps/named|/tiles/template)'; + // + var template_baseurl = global.environment.base_url_templated || '(?:/maps/named|/tiles/template)'; // Add a template ws.post(template_baseurl, function(req, res) { diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index 444a8794..458ffd23 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -26,12 +26,19 @@ module.exports = function(){ }); var me = { - base_url: '/tiles/:table', + // This is for inline maps and table maps + base_url: global.environment.base_url_legacy || '/tiles/:table', + /// @deprecated with Windshaft-0.17.0 - base_url_notable: '/tiles', + ///base_url_notable: '/tiles', + + // This is for Detached maps + // // "maps" is the official, while // "tiles/layergroup" is for backward compatibility up to 1.6.x - base_url_mapconfig: '(?:/maps|/tiles/layergroup)', + // + base_url_mapconfig: global.environment.base_url_detached || '(?:/maps|/tiles/layergroup)', + grainstore: { map: { // TODO: allow to specify in configuration