From 93edf07da87ab8746ef9116a13ac3e46ba3dc45e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Fri, 4 Oct 2019 12:35:12 +0200 Subject: [PATCH] Temporary workaround to not depend on configuration changes --- 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.js | 6 ++++++ 4 files changed, 22 insertions(+) diff --git a/lib/cartodb/api/api-router.js b/lib/cartodb/api/api-router.js index 08e5072d..5657f21f 100644 --- a/lib/cartodb/api/api-router.js +++ b/lib/cartodb/api/api-router.js @@ -202,6 +202,11 @@ 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 c5070627..7af5bd9d 100644 --- a/lib/cartodb/api/map/map-router.js +++ b/lib/cartodb/api/map/map-router.js @@ -129,6 +129,11 @@ 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 ecdc9802..2bad038d 100644 --- a/lib/cartodb/api/template/template-router.js +++ b/lib/cartodb/api/template/template-router.js @@ -57,6 +57,12 @@ 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.js b/lib/cartodb/server.js index d434c48b..01e68391 100644 --- a/lib/cartodb/server.js +++ b/lib/cartodb/server.js @@ -33,6 +33,12 @@ module.exports = function createServer (serverOptions) { app.set('json replacer', jsonReplacer()); const apiRouter = new ApiRouter({ serverOptions, environmentOptions: global.environment }); + + // TODO: remove it before releasing next major version + if (!Array.isArray(serverOptions.routes.api)) { + serverOptions.routes.api = [ serverOptions.routes.api ]; + } + apiRouter.route(app, serverOptions.routes.api); const versions = getAndValidateVersions(serverOptions);