2018-10-23 23:45:42 +08:00
|
|
|
'use strict';
|
|
|
|
|
2018-04-04 21:52:54 +08:00
|
|
|
const { Router: router } = require('express');
|
|
|
|
|
2018-04-09 22:18:30 +08:00
|
|
|
const NamedMapController = require('./named-template-controller');
|
|
|
|
const AdminTemplateController = require('./admin-template-controller');
|
|
|
|
const TileTemplateController = require('./tile-template-controller');
|
2018-04-04 21:52:54 +08:00
|
|
|
|
|
|
|
module.exports = class TemplateRouter {
|
2018-05-09 20:59:21 +08:00
|
|
|
constructor ({ collaborators }) {
|
2018-04-04 21:52:54 +08:00
|
|
|
const {
|
|
|
|
pgConnection,
|
|
|
|
templateMaps,
|
|
|
|
mapBackend,
|
|
|
|
metadataBackend,
|
|
|
|
surrogateKeysCache,
|
2018-04-10 16:16:07 +08:00
|
|
|
userLimitsBackend,
|
2018-04-04 21:52:54 +08:00
|
|
|
layergroupAffectedTablesCache,
|
|
|
|
mapConfigAdapter,
|
|
|
|
statsBackend,
|
2018-04-10 00:08:56 +08:00
|
|
|
authBackend,
|
2018-04-04 21:52:54 +08:00
|
|
|
layergroupMetadata,
|
|
|
|
namedMapProviderCache,
|
2019-10-22 01:07:24 +08:00
|
|
|
tileBackend
|
2018-04-04 21:52:54 +08:00
|
|
|
} = collaborators;
|
|
|
|
|
|
|
|
this.namedMapController = new NamedMapController(
|
|
|
|
pgConnection,
|
|
|
|
templateMaps,
|
|
|
|
mapBackend,
|
|
|
|
metadataBackend,
|
|
|
|
surrogateKeysCache,
|
2018-04-10 16:16:07 +08:00
|
|
|
userLimitsBackend,
|
2018-04-04 21:52:54 +08:00
|
|
|
layergroupAffectedTablesCache,
|
|
|
|
mapConfigAdapter,
|
|
|
|
statsBackend,
|
2018-04-10 00:08:56 +08:00
|
|
|
authBackend,
|
2018-04-04 21:52:54 +08:00
|
|
|
layergroupMetadata
|
|
|
|
);
|
|
|
|
|
|
|
|
this.tileTemplateController = new TileTemplateController(
|
|
|
|
namedMapProviderCache,
|
|
|
|
tileBackend,
|
|
|
|
surrogateKeysCache,
|
|
|
|
pgConnection,
|
2018-04-10 00:08:56 +08:00
|
|
|
authBackend,
|
2018-04-10 16:16:07 +08:00
|
|
|
userLimitsBackend
|
2018-04-04 21:52:54 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
this.adminTemplateController = new AdminTemplateController(
|
2018-04-10 00:08:56 +08:00
|
|
|
authBackend,
|
2018-04-04 21:52:54 +08:00
|
|
|
templateMaps,
|
2018-04-10 16:16:07 +08:00
|
|
|
userLimitsBackend
|
2018-04-04 21:52:54 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-10-04 18:22:23 +08:00
|
|
|
route (apiRouter, routes) {
|
2018-05-14 17:50:48 +08:00
|
|
|
const templateRouter = router({ mergeParams: true });
|
2018-04-04 21:52:54 +08:00
|
|
|
|
2019-10-04 18:07:58 +08:00
|
|
|
routes.forEach(route => {
|
|
|
|
const { paths, middlewares = [] } = route;
|
2019-10-01 01:18:24 +08:00
|
|
|
|
2019-10-04 18:07:58 +08:00
|
|
|
middlewares.forEach(middleware => templateRouter.use(middleware()));
|
2018-04-04 21:52:54 +08:00
|
|
|
|
2019-10-04 18:22:23 +08:00
|
|
|
this.namedMapController.route(templateRouter);
|
|
|
|
this.tileTemplateController.route(templateRouter);
|
|
|
|
this.adminTemplateController.route(templateRouter);
|
2019-10-04 18:07:58 +08:00
|
|
|
|
|
|
|
paths.forEach(path => apiRouter.use(path, templateRouter));
|
|
|
|
});
|
2018-04-04 21:52:54 +08:00
|
|
|
}
|
|
|
|
};
|