Run this script from GitHub Gist directly
npx https://gist.github.com/akunzai/e245cb079d90bf102b8a7bf60ef07536| {"name": "inspect-requests", "version": "1.0.0", "bin": "./server.js"} |
| #!/usr/bin/env node | |
| // see alternative tool at https://www.npmjs.com/package/reqon | |
| const http = require('http'); | |
| const port = process.argv[2] || 3000; | |
| const server = http.createServer((req, res) => { | |
| console.log('--- ', new Date().toISOString()); | |
| console.log(req.method, req.url); | |
| for (let header in req.headers) { | |
| console.log(`${header}: ${req.headers[header]}`); | |
| } | |
| let body = []; | |
| req.on('data', (chunk) => { | |
| body.push(chunk); | |
| }).on('end', () => { | |
| body = Buffer.concat(body).toString(); | |
| if (body.length > 0) { | |
| console.log(); | |
| console.log(body); | |
| } | |
| }); | |
| res.statusCode = 202; | |
| res.end(); | |
| }); | |
| server.listen(port); | |
| console.log(`Server running on port ${port}`); |