UNPKG

loopback-xtotalcount

Version:
20 lines (18 loc) 467 B
module.exports = function (app) { var remotes = app.remotes(); // Set X-Total-Count for all search requests remotes.after('*.find', function (ctx, next) { var filter; if (ctx.args && ctx.args.filter) { filter = JSON.parse(ctx.args.filter).where; } if (!ctx.res._headerSent) { this.count(filter, function (err, count) { ctx.res.set('X-Total-Count', count); next(); }); } else { next(); } }); };