Use config to define base path for express routers
This commit is contained in:
parent
ac615b4a25
commit
c0943a7c58
@ -176,8 +176,8 @@ module.exports = class ApiRouter {
|
|||||||
tablesExtentBackend
|
tablesExtentBackend
|
||||||
};
|
};
|
||||||
|
|
||||||
this.mapRouter = new MapRouter({ collaborators });
|
this.mapRouter = new MapRouter({ collaborators, serverOptions });
|
||||||
this.templateRouter = new TemplateRouter({ collaborators });
|
this.templateRouter = new TemplateRouter({ collaborators, serverOptions });
|
||||||
}
|
}
|
||||||
|
|
||||||
register (app) {
|
register (app) {
|
||||||
@ -206,12 +206,7 @@ module.exports = class ApiRouter {
|
|||||||
apiRouter.use(syntaxError());
|
apiRouter.use(syntaxError());
|
||||||
apiRouter.use(errorMiddleware());
|
apiRouter.use(errorMiddleware());
|
||||||
|
|
||||||
const paths = [
|
const paths = this.serverOptions.api_base_paths;
|
||||||
'/api/v1',
|
|
||||||
'/user/:user/api/v1',
|
|
||||||
'/tiles', // Deprecated
|
|
||||||
'/database/:dbname' // Deprecated: used in ported test from windshaft
|
|
||||||
];
|
|
||||||
|
|
||||||
app.use(`(?:${paths.join('|')})`, apiRouter);
|
app.use(`(?:${paths.join('|')})`, apiRouter);
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,9 @@ const PreviewTemplateController = require('./preview-template-controller');
|
|||||||
const AnalysesCatalogController = require('./analyses-catalog-controller');
|
const AnalysesCatalogController = require('./analyses-catalog-controller');
|
||||||
|
|
||||||
module.exports = class MapRouter {
|
module.exports = class MapRouter {
|
||||||
constructor ({ collaborators }) {
|
constructor ({ collaborators, serverOptions }) {
|
||||||
|
this.serverOptions = serverOptions;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
analysisStatusBackend,
|
analysisStatusBackend,
|
||||||
attributesBackend,
|
attributesBackend,
|
||||||
@ -127,10 +129,7 @@ module.exports = class MapRouter {
|
|||||||
this.previewTemplateController.register(mapRouter);
|
this.previewTemplateController.register(mapRouter);
|
||||||
this.analysesController.register(mapRouter);
|
this.analysesController.register(mapRouter);
|
||||||
|
|
||||||
const paths = [
|
const paths = this.serverOptions.map_base_paths;
|
||||||
'/map',
|
|
||||||
'/layergroup'
|
|
||||||
];
|
|
||||||
|
|
||||||
apiRouter.use(`(?:${paths.join('|')})`, mapRouter);
|
apiRouter.use(`(?:${paths.join('|')})`, mapRouter);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,9 @@ const AdminTemplateController = require('./admin-template-controller');
|
|||||||
const TileTemplateController = require('./tile-template-controller');
|
const TileTemplateController = require('./tile-template-controller');
|
||||||
|
|
||||||
module.exports = class TemplateRouter {
|
module.exports = class TemplateRouter {
|
||||||
constructor ({ collaborators }) {
|
constructor ({ collaborators, serverOptions }) {
|
||||||
|
this.serverOptions = serverOptions;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
pgConnection,
|
pgConnection,
|
||||||
templateMaps,
|
templateMaps,
|
||||||
@ -59,10 +61,7 @@ module.exports = class TemplateRouter {
|
|||||||
this.tileTemplateController.register(templateRouter);
|
this.tileTemplateController.register(templateRouter);
|
||||||
this.adminTemplateController.register(templateRouter);
|
this.adminTemplateController.register(templateRouter);
|
||||||
|
|
||||||
const paths = [
|
const paths = this.serverOptions.template_base_paths;
|
||||||
'/map/named',
|
|
||||||
'/template'
|
|
||||||
];
|
|
||||||
|
|
||||||
apiRouter.use(`(?:${paths.join('|')})`, templateRouter);
|
apiRouter.use(`(?:${paths.join('|')})`, templateRouter);
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,19 @@ 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 || [
|
||||||
|
'/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: {
|
grainstore: {
|
||||||
map: {
|
map: {
|
||||||
// TODO: allow to specify in configuration
|
// TODO: allow to specify in configuration
|
||||||
|
@ -11,6 +11,20 @@ module.exports = _.extend({}, serverOptions, {
|
|||||||
base_url: '/database/:dbname/table/:table',
|
base_url: '/database/:dbname/table/:table',
|
||||||
// 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: [
|
||||||
|
'/tiles',
|
||||||
|
'/database/:dbname'
|
||||||
|
],
|
||||||
|
|
||||||
|
map_base_paths: [
|
||||||
|
'/layergroup'
|
||||||
|
],
|
||||||
|
|
||||||
|
template_base_paths: [
|
||||||
|
'/template'
|
||||||
|
],
|
||||||
|
|
||||||
grainstore: {
|
grainstore: {
|
||||||
datasource: {
|
datasource: {
|
||||||
geometry_field: 'the_geom',
|
geometry_field: 'the_geom',
|
||||||
|
Loading…
Reference in New Issue
Block a user