越来越咸,两个月没发文章了,刚刚换项目了,开始学一些新的知识。
近来调试 webhook 和 http callback 比较多,想要使用 Node.js 写一个接收所有 HTTP 请求,并把请求头和请求体写进log,返回 200 OK 的 service。
其实就是简单的 access.log 啦。
其实就是刚学习 Node.js 写的 demo 啦。
啊这是很简单你不要拆穿啦。
这是输出的 log 的样子,优化了可读性,时间、method、path、URL参数(Query)、请求头(Header)、请求体(Body)都详细记录了:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| info: 2019-07-25 18:04:36 POST /v1.0/standard Query: search: keyword Header: cache-control: no-cache postman-token: f4103067-4b07-447d-9fab-f09a75b6ddda content-type: application/json user-agent: PostmanRuntime/3.0.11-hotfix.2 accept: */* host: localhost:4000 accept-encoding: gzip, deflate content-length: 209 connection: keep-alive Body: appId: XXX data: userId: 123 requestId: 456 timestamp: 0
|