Use config to define base path for express routers

This commit is contained in:
Daniel García Aubert 2018-04-10 20:26:36 +02:00
parent ac615b4a25
commit c0943a7c58
5 changed files with 38 additions and 18 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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

View File

@ -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',