From 43a63feaca075b5258cdc3462174e1a56b15f2df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Sun, 6 Oct 2019 18:58:21 +0200 Subject: [PATCH] Keep the backwards compatibility for routing configuration --- lib/cartodb/api/api-router.js | 5 -- lib/cartodb/api/map/map-router.js | 5 -- lib/cartodb/api/template/template-router.js | 6 --- lib/cartodb/server_options.js | 60 +++++++++++++-------- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/lib/cartodb/api/api-router.js b/lib/cartodb/api/api-router.js index 5657f21f..08e5072d 100644 --- a/lib/cartodb/api/api-router.js +++ b/lib/cartodb/api/api-router.js @@ -202,11 +202,6 @@ module.exports = class ApiRouter { app.layergroupAffectedTablesCache = this.layergroupAffectedTablesCache; } - // TODO: remove it before releasing next major version - if (!Array.isArray(routes)) { - routes = [ routes ]; - } - routes.forEach(route => { const apiRouter = router({ mergeParams: true }); const { paths, middlewares = [] } = route; diff --git a/lib/cartodb/api/map/map-router.js b/lib/cartodb/api/map/map-router.js index 7af5bd9d..c5070627 100644 --- a/lib/cartodb/api/map/map-router.js +++ b/lib/cartodb/api/map/map-router.js @@ -129,11 +129,6 @@ module.exports = class MapRouter { route (apiRouter, routes) { const mapRouter = router({ mergeParams: true }); - // TODO: remove it before releasing next major version - if (!Array.isArray(routes)) { - routes = [ routes ]; - } - routes.forEach(route => { const { paths, middlewares = [] } = route; diff --git a/lib/cartodb/api/template/template-router.js b/lib/cartodb/api/template/template-router.js index 2bad038d..ecdc9802 100644 --- a/lib/cartodb/api/template/template-router.js +++ b/lib/cartodb/api/template/template-router.js @@ -57,12 +57,6 @@ module.exports = class TemplateRouter { route (apiRouter, routes) { const templateRouter = router({ mergeParams: true }); - // TODO: remove it before releasing next major version - if (!Array.isArray(routes)) { - routes = [ routes ]; - } - - routes.forEach(route => { const { paths, middlewares = [] } = route; diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index 4772fac6..226153c5 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -58,6 +58,43 @@ var analysisConfig = _.defaults(global.environment.analysis || {}, { limits: {} }); +const routesConfig = global.environment.routes || { + api: [{ + paths: [ + '/api/v1', + '/user/:user/api/v1', + ], + // Base url for the Detached Maps API + // "/api/v1/map" is the new API, + map: [{ + paths: [ + '/map', + ] + }], + // Base url for the Templated Maps API + // "/api/v1/map/named" is the new API, + template: [{ + paths: [ + '/map/named' + ] + }] + }] +}; + +if (!Array.isArray(routesConfig.api)) { + routesConfig.api = [ routesConfig.api ]; +} + +routesConfig.api.forEach(route => { + if (!Array.isArray(route.map)) { + route.map = [ route.map ]; + } + + if (!Array.isArray(route.template)) { + route.template = [ route.template ]; + } +}); + module.exports = { bind: { port: global.environment.port, @@ -66,28 +103,7 @@ module.exports = { // Base URLs for the APIs // // See http://github.com/CartoDB/Windshaft-cartodb/wiki/Unified-Map-API - routes: global.environment.routes || { - api: { - paths: [ - '/api/v1', - '/user/:user/api/v1', - ], - // Base url for the Detached Maps API - // "/api/v1/map" is the new API, - map: [{ - paths: [ - '/map', - ] - }], - // Base url for the Templated Maps API - // "/api/v1/map/named" is the new API, - template: [{ - paths: [ - '/map/named' - ] - }] - } - }, + routes: routesConfig, grainstore: { map: { // TODO: allow to specify in configuration