diff --git a/lib/cartodb/api/api-router.js b/lib/cartodb/api/api-router.js index 7108bbbf..d75d23a5 100644 --- a/lib/cartodb/api/api-router.js +++ b/lib/cartodb/api/api-router.js @@ -176,8 +176,8 @@ module.exports = class ApiRouter { tablesExtentBackend }; - this.mapRouter = new MapRouter({ collaborators }); - this.templateRouter = new TemplateRouter({ collaborators }); + this.mapRouter = new MapRouter({ collaborators, serverOptions }); + this.templateRouter = new TemplateRouter({ collaborators, serverOptions }); } register (app) { @@ -206,12 +206,7 @@ module.exports = class ApiRouter { apiRouter.use(syntaxError()); apiRouter.use(errorMiddleware()); - const paths = [ - '/api/v1', - '/user/:user/api/v1', - '/tiles', // Deprecated - '/database/:dbname' // Deprecated: used in ported test from windshaft - ]; + const paths = this.serverOptions.api_base_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 a6e91c29..e8a3c2fb 100644 --- a/lib/cartodb/api/map/map-router.js +++ b/lib/cartodb/api/map/map-router.js @@ -10,7 +10,9 @@ const PreviewTemplateController = require('./preview-template-controller'); const AnalysesCatalogController = require('./analyses-catalog-controller'); module.exports = class MapRouter { - constructor ({ collaborators }) { + constructor ({ collaborators, serverOptions }) { + this.serverOptions = serverOptions; + const { analysisStatusBackend, attributesBackend, @@ -127,10 +129,7 @@ module.exports = class MapRouter { this.previewTemplateController.register(mapRouter); this.analysesController.register(mapRouter); - const paths = [ - '/map', - '/layergroup' - ]; + const paths = this.serverOptions.map_base_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 643e83c3..9b759f0a 100644 --- a/lib/cartodb/api/template/template-router.js +++ b/lib/cartodb/api/template/template-router.js @@ -5,7 +5,9 @@ const AdminTemplateController = require('./admin-template-controller'); const TileTemplateController = require('./tile-template-controller'); module.exports = class TemplateRouter { - constructor ({ collaborators }) { + constructor ({ collaborators, serverOptions }) { + this.serverOptions = serverOptions; + const { pgConnection, templateMaps, @@ -59,10 +61,7 @@ module.exports = class TemplateRouter { this.tileTemplateController.register(templateRouter); this.adminTemplateController.register(templateRouter); - const paths = [ - '/map/named', - '/template' - ]; + const paths = this.serverOptions.template_base_paths; apiRouter.use(`(?:${paths.join('|')})`, templateRouter); } diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index adc03003..c73a6bca 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -67,6 +67,19 @@ 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' + ], + grainstore: { map: { // TODO: allow to specify in configuration diff --git a/test/acceptance/ported/support/ported_server_options.js b/test/acceptance/ported/support/ported_server_options.js index 1ce262af..931fa584 100644 --- a/test/acceptance/ported/support/ported_server_options.js +++ b/test/acceptance/ported/support/ported_server_options.js @@ -11,6 +11,20 @@ module.exports = _.extend({}, serverOptions, { base_url: '/database/:dbname/table/:table', // 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' + ], + grainstore: { datasource: { geometry_field: 'the_geom',