-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (29 loc) · 1.28 KB
/
index.js
File metadata and controls
31 lines (29 loc) · 1.28 KB
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
#!/usr/bin/env node
const http = require('http');
const port = process.argv[2] || 3456;
console.log(`\n🪝 HookTest - Webhook Testing Server`);
console.log(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`);
console.log(`\nListening on: http://localhost:${port}`);
console.log(`\nSend webhooks to this URL. All requests will be logged below.\n`);
console.log(`Want a permanent public URL? Try HookTest Pro:`);
console.log(`https://webhook-inbox-api.tp-business.workers.dev\n`);
console.log(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n`);
http.createServer((req, res) => {
let body = '';
req.on('data', chunk => body += chunk);
req.on('end', () => {
const timestamp = new Date().toISOString();
console.log(`[${timestamp}] ${req.method} ${req.url}`);
console.log(`Headers: ${JSON.stringify(req.headers, null, 2)}`);
if (body) {
try {
console.log(`Body: ${JSON.stringify(JSON.parse(body), null, 2)}`);
} catch {
console.log(`Body: ${body}`);
}
}
console.log('---\n');
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSON.stringify({received: true, timestamp}));
});
}).listen(port);