Use new routes configuration
This commit is contained in:
parent
975f07df99
commit
dd06de2632
@ -20,7 +20,7 @@ var config = {
|
|||||||
// Note: each entry corresponds with an express' router.
|
// Note: each entry corresponds with an express' router.
|
||||||
// You must define at least one path. However, middlewares are optional.
|
// You must define at least one path. However, middlewares are optional.
|
||||||
,routes: {
|
,routes: {
|
||||||
api: {
|
api: [{
|
||||||
paths: [
|
paths: [
|
||||||
'/api/v1',
|
'/api/v1',
|
||||||
'/user/:user/api/v1',
|
'/user/:user/api/v1',
|
||||||
@ -36,21 +36,21 @@ var config = {
|
|||||||
],
|
],
|
||||||
// Base url for the Detached Maps API
|
// Base url for the Detached Maps API
|
||||||
// "/api/v1/map" is the new API,
|
// "/api/v1/map" is the new API,
|
||||||
map: {
|
map: [{
|
||||||
paths: [
|
paths: [
|
||||||
'/map',
|
'/map',
|
||||||
],
|
],
|
||||||
middlewares: [] // Optional
|
middlewares: [] // Optional
|
||||||
},
|
}],
|
||||||
// Base url for the Templated Maps API
|
// Base url for the Templated Maps API
|
||||||
// "/api/v1/map/named" is the new API,
|
// "/api/v1/map/named" is the new API,
|
||||||
template: {
|
template: [{
|
||||||
paths: [
|
paths: [
|
||||||
'/map/named'
|
'/map/named'
|
||||||
],
|
],
|
||||||
middlewares: [] // Optional
|
middlewares: [] // Optional
|
||||||
}
|
}]
|
||||||
}
|
}]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resource URLs expose endpoints to request/retrieve metadata associated to Maps: dataviews, analysis node status.
|
// Resource URLs expose endpoints to request/retrieve metadata associated to Maps: dataviews, analysis node status.
|
||||||
|
@ -20,7 +20,7 @@ var config = {
|
|||||||
// Note: each entry corresponds with an express' router.
|
// Note: each entry corresponds with an express' router.
|
||||||
// You must define at least one path. However, middlewares are optional.
|
// You must define at least one path. However, middlewares are optional.
|
||||||
,routes: {
|
,routes: {
|
||||||
api: {
|
api: [{
|
||||||
paths: [
|
paths: [
|
||||||
'/api/v1',
|
'/api/v1',
|
||||||
'/user/:user/api/v1',
|
'/user/:user/api/v1',
|
||||||
@ -36,21 +36,21 @@ var config = {
|
|||||||
],
|
],
|
||||||
// Base url for the Detached Maps API
|
// Base url for the Detached Maps API
|
||||||
// "/api/v1/map" is the new API,
|
// "/api/v1/map" is the new API,
|
||||||
map: {
|
map: [{
|
||||||
paths: [
|
paths: [
|
||||||
'/map',
|
'/map',
|
||||||
],
|
],
|
||||||
middlewares: [] // Optional
|
middlewares: [] // Optional
|
||||||
},
|
}],
|
||||||
// Base url for the Templated Maps API
|
// Base url for the Templated Maps API
|
||||||
// "/api/v1/map/named" is the new API,
|
// "/api/v1/map/named" is the new API,
|
||||||
template: {
|
template: [{
|
||||||
paths: [
|
paths: [
|
||||||
'/map/named'
|
'/map/named'
|
||||||
],
|
],
|
||||||
middlewares: [] // Optional
|
middlewares: [] // Optional
|
||||||
}
|
}]
|
||||||
}
|
}]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resource URLs expose endpoints to request/retrieve metadata associated to Maps: dataviews, analysis node status.
|
// Resource URLs expose endpoints to request/retrieve metadata associated to Maps: dataviews, analysis node status.
|
||||||
|
@ -20,7 +20,7 @@ var config = {
|
|||||||
// Note: each entry corresponds with an express' router.
|
// Note: each entry corresponds with an express' router.
|
||||||
// You must define at least one path. However, middlewares are optional.
|
// You must define at least one path. However, middlewares are optional.
|
||||||
,routes: {
|
,routes: {
|
||||||
api: {
|
api: [{
|
||||||
paths: [
|
paths: [
|
||||||
'/api/v1',
|
'/api/v1',
|
||||||
'/user/:user/api/v1',
|
'/user/:user/api/v1',
|
||||||
@ -36,21 +36,21 @@ var config = {
|
|||||||
],
|
],
|
||||||
// Base url for the Detached Maps API
|
// Base url for the Detached Maps API
|
||||||
// "/api/v1/map" is the new API,
|
// "/api/v1/map" is the new API,
|
||||||
map: {
|
map: [{
|
||||||
paths: [
|
paths: [
|
||||||
'/map',
|
'/map',
|
||||||
],
|
],
|
||||||
middlewares: [] // Optional
|
middlewares: [] // Optional
|
||||||
},
|
}],
|
||||||
// Base url for the Templated Maps API
|
// Base url for the Templated Maps API
|
||||||
// "/api/v1/map/named" is the new API,
|
// "/api/v1/map/named" is the new API,
|
||||||
template: {
|
template: [{
|
||||||
paths: [
|
paths: [
|
||||||
'/map/named'
|
'/map/named'
|
||||||
],
|
],
|
||||||
middlewares: [] // Optional
|
middlewares: [] // Optional
|
||||||
}
|
}]
|
||||||
}
|
}]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resource URLs expose endpoints to request/retrieve metadata associated to Maps: dataviews, analysis node status.
|
// Resource URLs expose endpoints to request/retrieve metadata associated to Maps: dataviews, analysis node status.
|
||||||
|
@ -20,7 +20,7 @@ var config = {
|
|||||||
// Note: each entry corresponds with an express' router.
|
// Note: each entry corresponds with an express' router.
|
||||||
// You must define at least one path. However, middlewares are optional.
|
// You must define at least one path. However, middlewares are optional.
|
||||||
,routes: {
|
,routes: {
|
||||||
api: {
|
api: [{
|
||||||
paths: [
|
paths: [
|
||||||
'/api/v1',
|
'/api/v1',
|
||||||
'/user/:user/api/v1',
|
'/user/:user/api/v1',
|
||||||
@ -36,21 +36,21 @@ var config = {
|
|||||||
],
|
],
|
||||||
// Base url for the Detached Maps API
|
// Base url for the Detached Maps API
|
||||||
// "/api/v1/map" is the new API,
|
// "/api/v1/map" is the new API,
|
||||||
map: {
|
map: [{
|
||||||
paths: [
|
paths: [
|
||||||
'/map',
|
'/map',
|
||||||
],
|
],
|
||||||
middlewares: [] // Optional
|
middlewares: [] // Optional
|
||||||
},
|
}],
|
||||||
// Base url for the Templated Maps API
|
// Base url for the Templated Maps API
|
||||||
// "/api/v1/map/named" is the new API,
|
// "/api/v1/map/named" is the new API,
|
||||||
template: {
|
template: [{
|
||||||
paths: [
|
paths: [
|
||||||
'/map/named'
|
'/map/named'
|
||||||
],
|
],
|
||||||
middlewares: [] // Optional
|
middlewares: [] // Optional
|
||||||
}
|
}]
|
||||||
}
|
}]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resource URLs expose endpoints to request/retrieve metadata associated to Maps: dataviews, analysis node status.
|
// Resource URLs expose endpoints to request/retrieve metadata associated to Maps: dataviews, analysis node status.
|
||||||
|
@ -196,13 +196,13 @@ module.exports = class ApiRouter {
|
|||||||
this.templateRouter = new TemplateRouter({ collaborators });
|
this.templateRouter = new TemplateRouter({ collaborators });
|
||||||
}
|
}
|
||||||
|
|
||||||
register (app) {
|
register (app, routes) {
|
||||||
// FIXME: we need a better way to reset cache while running tests
|
// FIXME: we need a better way to reset cache while running tests
|
||||||
if (process.env.NODE_ENV === 'test') {
|
if (process.env.NODE_ENV === 'test') {
|
||||||
app.layergroupAffectedTablesCache = this.layergroupAffectedTablesCache;
|
app.layergroupAffectedTablesCache = this.layergroupAffectedTablesCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.values(this.serverOptions.routes).forEach(route => {
|
routes.forEach(route => {
|
||||||
const apiRouter = router({ mergeParams: true });
|
const apiRouter = router({ mergeParams: true });
|
||||||
|
|
||||||
const apiPaths = route.paths;
|
const apiPaths = route.paths;
|
||||||
@ -222,8 +222,8 @@ module.exports = class ApiRouter {
|
|||||||
apiRouter.use(cors());
|
apiRouter.use(cors());
|
||||||
apiRouter.use(user());
|
apiRouter.use(user());
|
||||||
|
|
||||||
this.templateRouter.register(apiRouter, route.template.paths, route.template.middlewares);
|
this.templateRouter.register(apiRouter, route.template);
|
||||||
this.mapRouter.register(apiRouter, route.map.paths, route.map.middlewares);
|
this.mapRouter.register(apiRouter, route.map);
|
||||||
|
|
||||||
apiRouter.use(sendResponse());
|
apiRouter.use(sendResponse());
|
||||||
apiRouter.use(syntaxError());
|
apiRouter.use(syntaxError());
|
||||||
|
@ -126,21 +126,25 @@ module.exports = class MapRouter {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
register (apiRouter, mapPaths, mapMiddlewares = []) {
|
register (apiRouter, routes) {
|
||||||
const mapRouter = router({ mergeParams: true });
|
const mapRouter = router({ mergeParams: true });
|
||||||
|
|
||||||
mapMiddlewares.forEach(middleware => mapRouter.use(middleware()));
|
routes.forEach(route => {
|
||||||
|
const { paths, middlewares = [] } = route;
|
||||||
|
|
||||||
this.analysisLayergroupController.register(mapRouter);
|
middlewares.forEach(middleware => mapRouter.use(middleware()));
|
||||||
this.attributesLayergroupController.register(mapRouter);
|
|
||||||
this.dataviewLayergroupController.register(mapRouter);
|
|
||||||
this.previewLayergroupController.register(mapRouter);
|
|
||||||
this.tileLayergroupController.register(mapRouter);
|
|
||||||
this.anonymousMapController.register(mapRouter);
|
|
||||||
this.previewTemplateController.register(mapRouter);
|
|
||||||
this.analysesController.register(mapRouter);
|
|
||||||
this.clusteredFeaturesLayergroupController.register(mapRouter);
|
|
||||||
|
|
||||||
mapPaths.forEach(path => apiRouter.use(path, mapRouter));
|
this.analysisLayergroupController.register(mapRouter);
|
||||||
|
this.attributesLayergroupController.register(mapRouter);
|
||||||
|
this.dataviewLayergroupController.register(mapRouter);
|
||||||
|
this.previewLayergroupController.register(mapRouter);
|
||||||
|
this.tileLayergroupController.register(mapRouter);
|
||||||
|
this.anonymousMapController.register(mapRouter);
|
||||||
|
this.previewTemplateController.register(mapRouter);
|
||||||
|
this.analysesController.register(mapRouter);
|
||||||
|
this.clusteredFeaturesLayergroupController.register(mapRouter);
|
||||||
|
|
||||||
|
paths.forEach(path => apiRouter.use(path, mapRouter));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -54,15 +54,19 @@ module.exports = class TemplateRouter {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
register (apiRouter, templatePaths, templateMiddlewares = []) {
|
register (apiRouter, routes) {
|
||||||
const templateRouter = router({ mergeParams: true });
|
const templateRouter = router({ mergeParams: true });
|
||||||
|
|
||||||
templateMiddlewares.forEach(middleware => templateRouter.use(middleware()));
|
routes.forEach(route => {
|
||||||
|
const { paths, middlewares = [] } = route;
|
||||||
|
|
||||||
this.namedMapController.register(templateRouter);
|
middlewares.forEach(middleware => templateRouter.use(middleware()));
|
||||||
this.tileTemplateController.register(templateRouter);
|
|
||||||
this.adminTemplateController.register(templateRouter);
|
|
||||||
|
|
||||||
templatePaths.forEach(path => apiRouter.use(path, templateRouter));
|
this.namedMapController.register(templateRouter);
|
||||||
|
this.tileTemplateController.register(templateRouter);
|
||||||
|
this.adminTemplateController.register(templateRouter);
|
||||||
|
|
||||||
|
paths.forEach(path => apiRouter.use(path, templateRouter));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -33,7 +33,7 @@ module.exports = function createServer (serverOptions) {
|
|||||||
app.set('json replacer', jsonReplacer());
|
app.set('json replacer', jsonReplacer());
|
||||||
|
|
||||||
const apiRouter = new ApiRouter({ serverOptions, environmentOptions: global.environment });
|
const apiRouter = new ApiRouter({ serverOptions, environmentOptions: global.environment });
|
||||||
apiRouter.register(app);
|
apiRouter.register(app, serverOptions.routes.api);
|
||||||
|
|
||||||
const versions = getAndValidateVersions(serverOptions);
|
const versions = getAndValidateVersions(serverOptions);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user