-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (28 loc) · 856 Bytes
/
index.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
var express = require('express');
var router = express.Router();
var debug = require('debug')('hookhub-hook-dump');
debug("Loading");
// Get payload
router.use('/', function (req, res, next) {
if (req.method == 'GET') {
res.locals.payload = req.query;
} else if (req.method == 'POST') {
debug("Request Body:");
debug(req.body);
if (req.headers['content-type'].indexOf('application/json') && typeof req.body != 'object') {
debug("Converting to JSON");
res.locals.payload = JSON.parse(req.body);
} else {
res.locals.payload = req.body;
}
}
next();
});
/* Default handler. */
router.use('/', function(req, res, next) {
debug("Handling default request");
console.log("hookhub-hook-dump - payload:");
console.log(res.locals.payload);
res.send({result:"OK",ts:Date.now(),message:"Data Dumped"});
});
module.exports = router;