Use middleware for all requests

This commit is contained in:
Esther Lozano 2020-02-20 15:25:53 +01:00
parent 4a41ee8f75
commit e85469cc3c

View File

@ -25,6 +25,8 @@ const TablesExtentBackend = require('../backends/tables-extent');
const ClusterBackend = require('../backends/cluster'); const ClusterBackend = require('../backends/cluster');
const PubSubMetricsBackend = require('../backends/pubsub-metrics');
const LayergroupAffectedTablesCache = require('../cache/layergroup-affected-tables'); const LayergroupAffectedTablesCache = require('../cache/layergroup-affected-tables');
const SurrogateKeysCache = require('../cache/surrogate-keys-cache'); const SurrogateKeysCache = require('../cache/surrogate-keys-cache');
const VarnishHttpCacheBackend = require('../cache/backend/varnish-http'); const VarnishHttpCacheBackend = require('../cache/backend/varnish-http');
@ -59,6 +61,7 @@ const user = require('./middlewares/user');
const sendResponse = require('./middlewares/send-response'); const sendResponse = require('./middlewares/send-response');
const syntaxError = require('./middlewares/syntax-error'); const syntaxError = require('./middlewares/syntax-error');
const errorMiddleware = require('./middlewares/error-middleware'); const errorMiddleware = require('./middlewares/error-middleware');
const pubSubMetrics = require('./middlewares/pubsub-metrics');
const MapRouter = require('./map/map-router'); const MapRouter = require('./map/map-router');
const TemplateRouter = require('./template/template-router'); const TemplateRouter = require('./template/template-router');
@ -201,6 +204,7 @@ module.exports = class ApiRouter {
this.mapRouter = new MapRouter({ collaborators }); this.mapRouter = new MapRouter({ collaborators });
this.templateRouter = new TemplateRouter({ collaborators }); this.templateRouter = new TemplateRouter({ collaborators });
this.metadataBackend = metadataBackend; this.metadataBackend = metadataBackend;
this.pubSubMetricsBackend = PubSubMetricsBackend.build();
} }
route (app, routes) { route (app, routes) {
@ -233,6 +237,7 @@ module.exports = class ApiRouter {
apiRouter.use(sendResponse()); apiRouter.use(sendResponse());
apiRouter.use(syntaxError()); apiRouter.use(syntaxError());
apiRouter.use(errorMiddleware()); apiRouter.use(errorMiddleware());
apiRouter.use(pubSubMetrics(this.pubSubMetricsBackend));
paths.forEach(path => app.use(path, apiRouter)); paths.forEach(path => app.use(path, apiRouter));
}); });