From e06d3200c31f4e9e15b444980653d4c450f7f31e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Wed, 11 Apr 2018 12:33:07 +0200 Subject: [PATCH] Use a better API to define public routes --- lib/cartodb/api/api-router.js | 2 +- lib/cartodb/api/map/map-router.js | 2 +- lib/cartodb/api/template/template-router.js | 2 +- lib/cartodb/server_options.js | 30 +++++++++++-------- .../ported/support/ported_server_options.js | 30 +++++++++++-------- 5 files changed, 39 insertions(+), 27 deletions(-) diff --git a/lib/cartodb/api/api-router.js b/lib/cartodb/api/api-router.js index d75d23a5..b122a343 100644 --- a/lib/cartodb/api/api-router.js +++ b/lib/cartodb/api/api-router.js @@ -206,7 +206,7 @@ module.exports = class ApiRouter { apiRouter.use(syntaxError()); apiRouter.use(errorMiddleware()); - const paths = this.serverOptions.api_base_paths; + const paths = this.serverOptions.routes.api.paths; app.use(`(?:${paths.join('|')})`, apiRouter); } diff --git a/lib/cartodb/api/map/map-router.js b/lib/cartodb/api/map/map-router.js index e8a3c2fb..ae681168 100644 --- a/lib/cartodb/api/map/map-router.js +++ b/lib/cartodb/api/map/map-router.js @@ -129,7 +129,7 @@ module.exports = class MapRouter { this.previewTemplateController.register(mapRouter); this.analysesController.register(mapRouter); - const paths = this.serverOptions.map_base_paths; + const paths = this.serverOptions.routes.api.map.paths; apiRouter.use(`(?:${paths.join('|')})`, mapRouter); } diff --git a/lib/cartodb/api/template/template-router.js b/lib/cartodb/api/template/template-router.js index 9b759f0a..cfb883e7 100644 --- a/lib/cartodb/api/template/template-router.js +++ b/lib/cartodb/api/template/template-router.js @@ -61,7 +61,7 @@ module.exports = class TemplateRouter { this.tileTemplateController.register(templateRouter); this.adminTemplateController.register(templateRouter); - const paths = this.serverOptions.template_base_paths; + const paths = this.serverOptions.routes.api.template.paths; apiRouter.use(`(?:${paths.join('|')})`, templateRouter); } diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index c73a6bca..d05e5e1d 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -67,18 +67,24 @@ module.exports = { // FIXME: Remove it. This is no longer needed, paths are defined in routers base_url_templated: global.environment.base_url_templated || '(?:/maps/named|/tiles/template)', - api_base_paths: global.environment.api_base_paths || [ - '/api/v1', - '/user/:user/api/v1' - ], - - map_base_paths: global.environment.map_base_paths || [ - '/map' - ], - - template_base_paths: global.environment.template_base_paths || [ - '/map/named' - ], + routes: global.environment.routes || { + api: { + paths: [ + '/api/v1', + '/user/:user/api/v1' + ], + map: { + paths: [ + '/map' + ] + }, + template: { + paths: [ + '/map/named' + ] + } + } + }, grainstore: { map: { diff --git a/test/acceptance/ported/support/ported_server_options.js b/test/acceptance/ported/support/ported_server_options.js index 931fa584..d850b1c9 100644 --- a/test/acceptance/ported/support/ported_server_options.js +++ b/test/acceptance/ported/support/ported_server_options.js @@ -12,18 +12,24 @@ module.exports = _.extend({}, serverOptions, { // FIXME: Remove it. This is no longer needed, paths are defined in routers base_url_mapconfig: '/database/:dbname/layergroup', - api_base_paths: [ - '/tiles', - '/database/:dbname' - ], - - map_base_paths: [ - '/layergroup' - ], - - template_base_paths: [ - '/template' - ], + routes: { + api: { + paths: [ + '/tiles', + '/database/:dbname' + ], + map: { + paths: [ + '/layergroup' + ] + }, + template: { + paths: [ + '/template' + ] + } + } + }, grainstore: { datasource: {