Files
Windshaft-cartodb/lib/api/middlewares/increment-map-view-count.js
2020-05-26 13:15:35 +02:00

22 lines
662 B
JavaScript

'use strict';
module.exports = function incrementMapViewCount (metadataBackend) {
return function incrementMapViewCountMiddleware (req, res, next) {
const { mapConfig, user } = res.locals;
const statTag = mapConfig.obj().stat_tag;
res.set('Carto-Stat-Tag', `${statTag}`);
// Error won't blow up, just be logged.
metadataBackend.incMapviewCount(user, statTag, (err) => {
req.profiler.done('incMapviewCount');
if (err) {
global.logger.log(`ERROR: failed to increment mapview count for user '${user}': ${err.message}`);
}
next();
});
};
};