Use new routes configuration

This commit is contained in:
Daniel García Aubert 2019-10-04 12:07:58 +02:00
parent 975f07df99
commit dd06de2632
8 changed files with 55 additions and 47 deletions

View File

@ -20,7 +20,7 @@ var config = {
// Note: each entry corresponds with an express' router.
// You must define at least one path. However, middlewares are optional.
,routes: {
api: {
api: [{
paths: [
'/api/v1',
'/user/:user/api/v1',
@ -36,21 +36,21 @@ var config = {
],
// Base url for the Detached Maps API
// "/api/v1/map" is the new API,
map: {
map: [{
paths: [
'/map',
],
middlewares: [] // Optional
},
}],
// Base url for the Templated Maps API
// "/api/v1/map/named" is the new API,
template: {
template: [{
paths: [
'/map/named'
],
middlewares: [] // Optional
}
}
}]
}]
}
// Resource URLs expose endpoints to request/retrieve metadata associated to Maps: dataviews, analysis node status.

View File

@ -20,7 +20,7 @@ var config = {
// Note: each entry corresponds with an express' router.
// You must define at least one path. However, middlewares are optional.
,routes: {
api: {
api: [{
paths: [
'/api/v1',
'/user/:user/api/v1',
@ -36,21 +36,21 @@ var config = {
],
// Base url for the Detached Maps API
// "/api/v1/map" is the new API,
map: {
map: [{
paths: [
'/map',
],
middlewares: [] // Optional
},
}],
// Base url for the Templated Maps API
// "/api/v1/map/named" is the new API,
template: {
template: [{
paths: [
'/map/named'
],
middlewares: [] // Optional
}
}
}]
}]
}
// Resource URLs expose endpoints to request/retrieve metadata associated to Maps: dataviews, analysis node status.

View File

@ -20,7 +20,7 @@ var config = {
// Note: each entry corresponds with an express' router.
// You must define at least one path. However, middlewares are optional.
,routes: {
api: {
api: [{
paths: [
'/api/v1',
'/user/:user/api/v1',
@ -36,21 +36,21 @@ var config = {
],
// Base url for the Detached Maps API
// "/api/v1/map" is the new API,
map: {
map: [{
paths: [
'/map',
],
middlewares: [] // Optional
},
}],
// Base url for the Templated Maps API
// "/api/v1/map/named" is the new API,
template: {
template: [{
paths: [
'/map/named'
],
middlewares: [] // Optional
}
}
}]
}]
}
// Resource URLs expose endpoints to request/retrieve metadata associated to Maps: dataviews, analysis node status.

View File

@ -20,7 +20,7 @@ var config = {
// Note: each entry corresponds with an express' router.
// You must define at least one path. However, middlewares are optional.
,routes: {
api: {
api: [{
paths: [
'/api/v1',
'/user/:user/api/v1',
@ -36,21 +36,21 @@ var config = {
],
// Base url for the Detached Maps API
// "/api/v1/map" is the new API,
map: {
map: [{
paths: [
'/map',
],
middlewares: [] // Optional
},
}],
// Base url for the Templated Maps API
// "/api/v1/map/named" is the new API,
template: {
template: [{
paths: [
'/map/named'
],
middlewares: [] // Optional
}
}
}]
}]
}
// Resource URLs expose endpoints to request/retrieve metadata associated to Maps: dataviews, analysis node status.

View File

@ -196,13 +196,13 @@ module.exports = class ApiRouter {
this.templateRouter = new TemplateRouter({ collaborators });
}
register (app) {
register (app, routes) {
// FIXME: we need a better way to reset cache while running tests
if (process.env.NODE_ENV === 'test') {
app.layergroupAffectedTablesCache = this.layergroupAffectedTablesCache;
}
Object.values(this.serverOptions.routes).forEach(route => {
routes.forEach(route => {
const apiRouter = router({ mergeParams: true });
const apiPaths = route.paths;
@ -222,8 +222,8 @@ module.exports = class ApiRouter {
apiRouter.use(cors());
apiRouter.use(user());
this.templateRouter.register(apiRouter, route.template.paths, route.template.middlewares);
this.mapRouter.register(apiRouter, route.map.paths, route.map.middlewares);
this.templateRouter.register(apiRouter, route.template);
this.mapRouter.register(apiRouter, route.map);
apiRouter.use(sendResponse());
apiRouter.use(syntaxError());

View File

@ -126,10 +126,13 @@ module.exports = class MapRouter {
);
}
register (apiRouter, mapPaths, mapMiddlewares = []) {
register (apiRouter, routes) {
const mapRouter = router({ mergeParams: true });
mapMiddlewares.forEach(middleware => mapRouter.use(middleware()));
routes.forEach(route => {
const { paths, middlewares = [] } = route;
middlewares.forEach(middleware => mapRouter.use(middleware()));
this.analysisLayergroupController.register(mapRouter);
this.attributesLayergroupController.register(mapRouter);
@ -141,6 +144,7 @@ module.exports = class MapRouter {
this.analysesController.register(mapRouter);
this.clusteredFeaturesLayergroupController.register(mapRouter);
mapPaths.forEach(path => apiRouter.use(path, mapRouter));
paths.forEach(path => apiRouter.use(path, mapRouter));
});
}
};

View File

@ -54,15 +54,19 @@ module.exports = class TemplateRouter {
);
}
register (apiRouter, templatePaths, templateMiddlewares = []) {
register (apiRouter, routes) {
const templateRouter = router({ mergeParams: true });
templateMiddlewares.forEach(middleware => templateRouter.use(middleware()));
routes.forEach(route => {
const { paths, middlewares = [] } = route;
middlewares.forEach(middleware => templateRouter.use(middleware()));
this.namedMapController.register(templateRouter);
this.tileTemplateController.register(templateRouter);
this.adminTemplateController.register(templateRouter);
templatePaths.forEach(path => apiRouter.use(path, templateRouter));
paths.forEach(path => apiRouter.use(path, templateRouter));
});
}
};

View File

@ -33,7 +33,7 @@ module.exports = function createServer (serverOptions) {
app.set('json replacer', jsonReplacer());
const apiRouter = new ApiRouter({ serverOptions, environmentOptions: global.environment });
apiRouter.register(app);
apiRouter.register(app, serverOptions.routes.api);
const versions = getAndValidateVersions(serverOptions);