-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
61 lines (52 loc) · 1.41 KB
/
app.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const express = require('express');
const bodyParser = require('body-parser');
const http = require('http');
const socketIO = require('socket.io');
const app = express();
app.set('view engine', 'ejs');
app.use(express.static('public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
const requests = [];
app.get('/', (req, res) => {
res.render('index', {
requests
});
});
app.post('/clear', (req, res) => {
requests.length = 0;
io.emit('clear_requests');
res.status(200).send('All requests cleared.');
});
app.post('/webhook', (req, res) => {
const timestamp = new Date();
const request = {
id: timestamp.getTime(),
timestamp,
method: req.method,
headers: req.headers,
body: req.body,
};
requests.unshift(request);
io.emit('new_request', request);
res.status(200).send('Webhook received.');
});
app.get('/request/:id', (req, res) => {
const requestId = parseInt(req.params.id, 10);
const request = requests.find((r) => r.id === requestId);
if (request) {
res.render('request', {
request
});
} else {
res.status(404).send('Request not found.');
}
});
const server = http.createServer(app);
const io = socketIO(server);
const PORT = process.env.PORT || 3001;
server.listen(PORT, () => {
console.log(`Webhook debugger listening on port ${PORT}`);
});