Windshaft-cartodb/lib/api/middlewares/increment-map-view-count.js
Daniel García Aubert 163c546236 Replace log4js by pino as logger:
- Logs to stdout, disabled while testing
- Change log calls signature when needed
- Use development version of camshaft
- Removes unused log cofiguration
- Bind request id to log req/res
- Log req at the begining of the cycle and res at the end
2020-06-01 19:18:15 +02:00

24 lines
689 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;
if (statTag) {
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.warn(err, `ERROR: failed to increment mapview count for user '${user}'`);
}
next();
});
};
};