-
Notifications
You must be signed in to change notification settings - Fork 6
/
helpers.js
45 lines (36 loc) · 1.69 KB
/
helpers.js
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
37
38
39
40
41
42
43
44
45
const util = require('util');
let methods = {}
// log entire request
methods.logRequest = function(req) {
console.log(`>>> request headers <<<\n`, util.inspect(req.headers, {showHidden: false, depth: null, colors: true, compact: false}));
console.log(`>>> request query string <<<\n`, util.inspect(req.query, {showHidden: false, depth: null, colors: true, compact: false}));
console.log(`>>> request body <<<\n`, util.inspect(req.body, {showHidden: false, depth: null, colors: true, compact: false}));
}
// log just the request body
methods.logBody = function(req) {
console.log(`>>> request body <<<\n`, util.inspect(req.body, {showHidden: false, depth: null, colors: true, compact: false}));
return req.body;
}
// parse event hook request payload
methods.logEventHookRequest = function(req) {
req.body['events'].forEach(function(event) {
console.log(`displayMessage:\n`, util.inspect(event.displayMessage, {showHidden: false, depth: null, colors: true, compact: false}));
console.log(`actor:\n`, util.inspect(event.actor, {showHidden: false, depth: null, colors: true, compact: false}));
console.log(`target:\n`, util.inspect(event.target, {showHidden: false, depth: null, colors: true, compact: false}));
console.log(`outcome:\n`, util.inspect(event.outcome, {showHidden: false, depth: null, colors: true, compact: false}));
});
}
/**
* Parses the domain from an email address
* @param {string} emailAddress - An RFC5322 email address (i.e. "[email protected]")
* @return {string} - A domain (i.e. "example.com")
*/
methods.parseEmailDomain = function(emailAddress) {
return emailAddress.slice(emailAddress.indexOf('@')+1)
}
/**
*
* Expose methods
*
**/
module.exports = methods;