-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmiddleware.js
More file actions
36 lines (29 loc) · 717 Bytes
/
middleware.js
File metadata and controls
36 lines (29 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
const Solr = module.parent.exports;
const async = require('async');
const Middleware = {};
Middleware.ping = function (req, res, next) {
Solr.ping(function (err, response) {
res.locals.ping = !err ? response : undefined;
next();
});
};
Middleware.getEnabled = function (req, res, next) {
res.locals.enabled = parseInt(Solr.config.enabled, 10) || false;
next();
};
Middleware.getStats = function (req, res, next) {
async.parallel({
count: async.apply(Solr.getRecordCount),
topics: async.apply(Solr.getTopicCount),
}, function (err, data) {
if (!err) {
res.locals.stats = {
total: data.count,
topics: data.topics,
};
}
next();
});
};
module.exports = Middleware;