Skip to content

Instantly share code, notes, and snippets.

@cfjedimaster
Created January 25, 2024 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfjedimaster/73ad222fe89daaa6e1940376bfd5b34d to your computer and use it in GitHub Desktop.
Save cfjedimaster/73ad222fe89daaa6e1940376bfd5b34d to your computer and use it in GitHub Desktop.
/*
Used to debug webhook notifications.
Will need to be used with ngrok.
Thanks to Todd Sharp for the base code I modified.
*/
import * as http from 'http';
async function handler(req, res) {
console.log('Entered webhook handler.');
let body = '';
req.on('data', chunk => {
body += chunk.toString();
});
req.on('end', async () => {
console.log('BODY:\n', JSON.stringify(JSON.parse(body), null, '\t'));
// If you specified additional headers (see createpdf2.js), it will show up there:
console.log('HEADERS:\n',req.headers);
// Always respond with ack
res.writeHead(200, { 'Content-Type':'application/json' });
res.write(JSON.stringify({'ack':'done'}));
res.end();
});
}
const server = http.createServer(handler);
server.listen(3000);
console.log('Listening on port 3000');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment