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

77 lines
2.2 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 {
config,
pgConnection,
templateMaps,
mapBackend,
metadataBackend,
surrogateKeysCache,
userLimitsBackend,
layergroupAffectedTablesCache,
mapConfigAdapter,
statsBackend,
2018-04-10 00:08:56 +08:00
authBackend,
layergroupMetadata,
namedMapProviderCache,
tileBackend,
metricsBackend
} = collaborators;
this.namedMapController = new NamedMapController(
config,
pgConnection,
templateMaps,
mapBackend,
metadataBackend,
surrogateKeysCache,
userLimitsBackend,
layergroupAffectedTablesCache,
mapConfigAdapter,
statsBackend,
2018-04-10 00:08:56 +08:00
authBackend,
layergroupMetadata,
metricsBackend
);
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));
});
}
};