Rename method 'register' -> 'route'
This commit is contained in:
parent
dd06de2632
commit
a684bead92
@ -196,7 +196,7 @@ module.exports = class ApiRouter {
|
||||
this.templateRouter = new TemplateRouter({ collaborators });
|
||||
}
|
||||
|
||||
register (app, routes) {
|
||||
route (app, routes) {
|
||||
// FIXME: we need a better way to reset cache while running tests
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
app.layergroupAffectedTablesCache = this.layergroupAffectedTablesCache;
|
||||
@ -204,11 +204,9 @@ module.exports = class ApiRouter {
|
||||
|
||||
routes.forEach(route => {
|
||||
const apiRouter = router({ mergeParams: true });
|
||||
const { paths, middlewares = [] } = route;
|
||||
|
||||
const apiPaths = route.paths;
|
||||
const apiMiddlewares = route.middlewares || [];
|
||||
|
||||
apiMiddlewares.forEach(middleware => apiRouter.use(middleware()));
|
||||
middlewares.forEach(middleware => apiRouter.use(middleware()));
|
||||
|
||||
apiRouter.use(logger(this.serverOptions));
|
||||
apiRouter.use(initializeStatusCode());
|
||||
@ -222,14 +220,14 @@ module.exports = class ApiRouter {
|
||||
apiRouter.use(cors());
|
||||
apiRouter.use(user());
|
||||
|
||||
this.templateRouter.register(apiRouter, route.template);
|
||||
this.mapRouter.register(apiRouter, route.map);
|
||||
this.templateRouter.route(apiRouter, route.template);
|
||||
this.mapRouter.route(apiRouter, route.map);
|
||||
|
||||
apiRouter.use(sendResponse());
|
||||
apiRouter.use(syntaxError());
|
||||
apiRouter.use(errorMiddleware());
|
||||
|
||||
apiPaths.forEach(path => app.use(path, apiRouter));
|
||||
paths.forEach(path => app.use(path, apiRouter));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -17,7 +17,7 @@ module.exports = class AnalysesController {
|
||||
this.userLimitsBackend = userLimitsBackend;
|
||||
}
|
||||
|
||||
register (mapRouter) {
|
||||
route (mapRouter) {
|
||||
mapRouter.get('/analyses/catalog', this.middlewares());
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ module.exports = class AnalysisLayergroupController {
|
||||
this.authBackend = authBackend;
|
||||
}
|
||||
|
||||
register (mapRouter) {
|
||||
route (mapRouter) {
|
||||
mapRouter.get('/:token/analysis/node/:nodeId', this.middlewares());
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ module.exports = class AnonymousMapController {
|
||||
this.layergroupMetadata = layergroupMetadata;
|
||||
}
|
||||
|
||||
register (mapRouter) {
|
||||
route (mapRouter) {
|
||||
mapRouter.options('/');
|
||||
mapRouter.get('/', this.middlewares());
|
||||
mapRouter.post('/', this.middlewares());
|
||||
|
@ -32,7 +32,7 @@ module.exports = class AttributesLayergroupController {
|
||||
this.surrogateKeysCache = surrogateKeysCache;
|
||||
}
|
||||
|
||||
register (mapRouter) {
|
||||
route (mapRouter) {
|
||||
mapRouter.get('/:token/:layer/attributes/:fid', this.middlewares());
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ module.exports = class AggregatedFeaturesLayergroupController {
|
||||
this.surrogateKeysCache = surrogateKeysCache;
|
||||
}
|
||||
|
||||
register (mapRouter) {
|
||||
route (mapRouter) {
|
||||
mapRouter.get('/:token/:layer/:z/cluster/:clusterId', this.middlewares());
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ module.exports = class DataviewLayergroupController {
|
||||
this.surrogateKeysCache = surrogateKeysCache;
|
||||
}
|
||||
|
||||
register (mapRouter) {
|
||||
route (mapRouter) {
|
||||
// Undocumented/non-supported API endpoint methods.
|
||||
// Use at your own peril.
|
||||
|
||||
|
@ -126,7 +126,7 @@ module.exports = class MapRouter {
|
||||
);
|
||||
}
|
||||
|
||||
register (apiRouter, routes) {
|
||||
route (apiRouter, routes) {
|
||||
const mapRouter = router({ mergeParams: true });
|
||||
|
||||
routes.forEach(route => {
|
||||
@ -134,15 +134,15 @@ module.exports = class MapRouter {
|
||||
|
||||
middlewares.forEach(middleware => mapRouter.use(middleware()));
|
||||
|
||||
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);
|
||||
this.analysisLayergroupController.route(mapRouter);
|
||||
this.attributesLayergroupController.route(mapRouter);
|
||||
this.dataviewLayergroupController.route(mapRouter);
|
||||
this.previewLayergroupController.route(mapRouter);
|
||||
this.tileLayergroupController.route(mapRouter);
|
||||
this.anonymousMapController.route(mapRouter);
|
||||
this.previewTemplateController.route(mapRouter);
|
||||
this.analysesController.route(mapRouter);
|
||||
this.clusteredFeaturesLayergroupController.route(mapRouter);
|
||||
|
||||
paths.forEach(path => apiRouter.use(path, mapRouter));
|
||||
});
|
||||
|
@ -35,7 +35,7 @@ module.exports = class PreviewLayergroupController {
|
||||
this.surrogateKeysCache = surrogateKeysCache;
|
||||
}
|
||||
|
||||
register (mapRouter) {
|
||||
route (mapRouter) {
|
||||
mapRouter.get('/static/center/:token/:z/:lat/:lng/:width/:height.:format', this.middlewares({
|
||||
validateZoom: true,
|
||||
previewType: 'centered'
|
||||
|
@ -46,7 +46,7 @@ module.exports = class PreviewTemplateController {
|
||||
this.userLimitsBackend = userLimitsBackend;
|
||||
}
|
||||
|
||||
register (mapRouter) {
|
||||
route (mapRouter) {
|
||||
mapRouter.get('/static/named/:template_id/:width/:height.:format', this.middlewares());
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ module.exports = class TileLayergroupController {
|
||||
this.surrogateKeysCache = surrogateKeysCache;
|
||||
}
|
||||
|
||||
register (mapRouter) {
|
||||
route (mapRouter) {
|
||||
// REGEXP: doesn't match with `val`
|
||||
const not = (val) => `(?!${val})([^\/]+?)`;
|
||||
|
||||
|
@ -18,7 +18,7 @@ module.exports = class AdminTemplateController {
|
||||
this.userLimitsBackend = userLimitsBackend;
|
||||
}
|
||||
|
||||
register (templateRouter) {
|
||||
route (templateRouter) {
|
||||
templateRouter.options(`/:template_id`);
|
||||
|
||||
templateRouter.post('/', this.middlewares({
|
||||
|
@ -63,7 +63,7 @@ module.exports = class NamedMapController {
|
||||
this.layergroupMetadata = layergroupMetadata;
|
||||
}
|
||||
|
||||
register (templateRouter) {
|
||||
route (templateRouter) {
|
||||
templateRouter.get('/:template_id/jsonp', this.middlewares());
|
||||
templateRouter.post('/:template_id', this.middlewares());
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ module.exports = class TemplateRouter {
|
||||
);
|
||||
}
|
||||
|
||||
register (apiRouter, routes) {
|
||||
route (apiRouter, routes) {
|
||||
const templateRouter = router({ mergeParams: true });
|
||||
|
||||
routes.forEach(route => {
|
||||
@ -62,9 +62,9 @@ module.exports = class TemplateRouter {
|
||||
|
||||
middlewares.forEach(middleware => templateRouter.use(middleware()));
|
||||
|
||||
this.namedMapController.register(templateRouter);
|
||||
this.tileTemplateController.register(templateRouter);
|
||||
this.adminTemplateController.register(templateRouter);
|
||||
this.namedMapController.route(templateRouter);
|
||||
this.tileTemplateController.route(templateRouter);
|
||||
this.adminTemplateController.route(templateRouter);
|
||||
|
||||
paths.forEach(path => apiRouter.use(path, templateRouter));
|
||||
});
|
||||
|
@ -31,7 +31,7 @@ module.exports = class TileTemplateController {
|
||||
this.userLimitsBackend = userLimitsBackend;
|
||||
}
|
||||
|
||||
register (templateRouter) {
|
||||
route (templateRouter) {
|
||||
templateRouter.get('/:template_id/:layer/:z/:x/:y.(:format)', this.middlewares());
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ function ServerInfoController(versions) {
|
||||
|
||||
module.exports = ServerInfoController;
|
||||
|
||||
ServerInfoController.prototype.register = function(monitorRouter) {
|
||||
ServerInfoController.prototype.route = function(monitorRouter) {
|
||||
monitorRouter.get('/health', this.health.bind(this));
|
||||
monitorRouter.get('/', this.welcome.bind(this));
|
||||
monitorRouter.get('/version', this.version.bind(this));
|
||||
|
@ -33,12 +33,12 @@ module.exports = function createServer (serverOptions) {
|
||||
app.set('json replacer', jsonReplacer());
|
||||
|
||||
const apiRouter = new ApiRouter({ serverOptions, environmentOptions: global.environment });
|
||||
apiRouter.register(app, serverOptions.routes.api);
|
||||
apiRouter.route(app, serverOptions.routes.api);
|
||||
|
||||
const versions = getAndValidateVersions(serverOptions);
|
||||
|
||||
const serverInfoController = new ServerInfoController(versions);
|
||||
serverInfoController.register(app);
|
||||
serverInfoController.route(app);
|
||||
|
||||
return app;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user