-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathping.js
More file actions
36 lines (29 loc) · 960 Bytes
/
ping.js
File metadata and controls
36 lines (29 loc) · 960 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
const Promise = require('bluebird')
const _ = require('lodash')
const debug = require('debug')('loopback:component:ping')
const health = require('express-ping-win-posix')
module.exports = function pingModelFn(Ping, options) {
// Because lodash does not have a built-in method to sort an object by key
function sortObj(obj) {
return _(obj).toPairs().sortBy(0).fromPairs().value()
}
Ping.ping = parts => new Promise((resolve, reject) => {
parts = parts || options.parts
health.info((err, data) => {
if (err) {
return reject(err)
}
// Add the ENV VARS to the results
data.environment = sortObj(process.env)
// Remove the parts that are disabled in the config
_.forEach(parts, (value, part) => {
if (value === false) {
debug(`Removing part '${part}' from result`)
delete data[part]
}
})
return resolve(sortObj(data))
})
})
return Ping
}