Use a better API to define public routes

This commit is contained in:
Daniel García Aubert 2018-04-11 12:33:07 +02:00
parent c0943a7c58
commit e06d3200c3
5 changed files with 39 additions and 27 deletions

View File

@ -206,7 +206,7 @@ module.exports = class ApiRouter {
apiRouter.use(syntaxError()); apiRouter.use(syntaxError());
apiRouter.use(errorMiddleware()); apiRouter.use(errorMiddleware());
const paths = this.serverOptions.api_base_paths; const paths = this.serverOptions.routes.api.paths;
app.use(`(?:${paths.join('|')})`, apiRouter); app.use(`(?:${paths.join('|')})`, apiRouter);
} }

View File

@ -129,7 +129,7 @@ module.exports = class MapRouter {
this.previewTemplateController.register(mapRouter); this.previewTemplateController.register(mapRouter);
this.analysesController.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); apiRouter.use(`(?:${paths.join('|')})`, mapRouter);
} }

View File

@ -61,7 +61,7 @@ module.exports = class TemplateRouter {
this.tileTemplateController.register(templateRouter); this.tileTemplateController.register(templateRouter);
this.adminTemplateController.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); apiRouter.use(`(?:${paths.join('|')})`, templateRouter);
} }

View File

@ -67,18 +67,24 @@ module.exports = {
// FIXME: Remove it. This is no longer needed, paths are defined in routers // 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)', base_url_templated: global.environment.base_url_templated || '(?:/maps/named|/tiles/template)',
api_base_paths: global.environment.api_base_paths || [ routes: global.environment.routes || {
'/api/v1', api: {
'/user/:user/api/v1' paths: [
], '/api/v1',
'/user/:user/api/v1'
map_base_paths: global.environment.map_base_paths || [ ],
'/map' map: {
], paths: [
'/map'
template_base_paths: global.environment.template_base_paths || [ ]
'/map/named' },
], template: {
paths: [
'/map/named'
]
}
}
},
grainstore: { grainstore: {
map: { map: {

View File

@ -12,18 +12,24 @@ module.exports = _.extend({}, serverOptions, {
// FIXME: Remove it. This is no longer needed, paths are defined in routers // FIXME: Remove it. This is no longer needed, paths are defined in routers
base_url_mapconfig: '/database/:dbname/layergroup', base_url_mapconfig: '/database/:dbname/layergroup',
api_base_paths: [ routes: {
'/tiles', api: {
'/database/:dbname' paths: [
], '/tiles',
'/database/:dbname'
map_base_paths: [ ],
'/layergroup' map: {
], paths: [
'/layergroup'
template_base_paths: [ ]
'/template' },
], template: {
paths: [
'/template'
]
}
}
},
grainstore: { grainstore: {
datasource: { datasource: {