Windshaft-cartodb/lib/api/template/template-router.js

73 lines
2.1 KiB
JavaScript
Raw Normal View History

'use strict';
const { Router: router } = require('express');
const NamedMapController = require('./named-template-controller');
const AdminTemplateController = require('./admin-template-controller');
const TileTemplateController = require('./tile-template-controller');
module.exports = class TemplateRouter {
constructor ({ collaborators }) {
const {
pgConnection,
templateMaps,
mapBackend,
metadataBackend,
surrogateKeysCache,
userLimitsBackend,
layergroupAffectedTablesCache,
mapConfigAdapter,
statsBackend,
2018-04-10 00:08:56 +08:00
authBackend,
layergroupMetadata,
namedMapProviderCache,
2019-10-22 01:07:24 +08:00
tileBackend
} = collaborators;
this.namedMapController = new NamedMapController(
pgConnection,
templateMaps,
mapBackend,
metadataBackend,
surrogateKeysCache,
userLimitsBackend,
layergroupAffectedTablesCache,
mapConfigAdapter,
statsBackend,
2018-04-10 00:08:56 +08:00
authBackend,
layergroupMetadata
);
this.tileTemplateController = new TileTemplateController(
namedMapProviderCache,
tileBackend,
surrogateKeysCache,
pgConnection,
2018-04-10 00:08:56 +08:00
authBackend,
userLimitsBackend
);
this.adminTemplateController = new AdminTemplateController(
2018-04-10 00:08:56 +08:00
authBackend,
templateMaps,
userLimitsBackend
);
}
2019-10-04 18:22:23 +08:00
route (apiRouter, routes) {
const templateRouter = router({ mergeParams: true });
2019-10-04 18:07:58 +08:00
routes.forEach(route => {
const { paths, middlewares = [] } = route;
2019-10-04 18:07:58 +08:00
middlewares.forEach(middleware => templateRouter.use(middleware()));
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));
});
}
};