lws-request-monitor
Advanced tools
Comparing version 0.1.0 to 0.1.1
16
index.js
module.exports = MiddlewareBase => class RequestMonitor extends MiddlewareBase { | ||
middleware () { | ||
return async (ctx, next) => { | ||
const util = require('util') | ||
/* first, inspect the request */ | ||
const reqInfo = { | ||
@@ -11,5 +14,15 @@ socketId: ctx.req.socket.id, | ||
} | ||
if (ctx.request.body) reqInfo.data = ctx.request.body | ||
if (ctx.request.rawBody) reqInfo.data = ctx.request.rawBody | ||
const incomingBuffer = ctx.req._readableState.buffer | ||
if (!reqInfo.data && incomingBuffer.head && incomingBuffer.head.data.length) { | ||
reqInfo.data = '__INCOMING__' | ||
reqInfo.data[util.inspect.custom] = function (depth, options) { | ||
const byteSize = require('byte-size') | ||
const size = byteSize(incomingBuffer.head.data.length) | ||
return options.stylize(`[ incoming data (${size} so far) ]`, 'special') | ||
} | ||
} | ||
this.emit('verbose', 'server.request', reqInfo) | ||
/* next, inspect the response */ | ||
await next() | ||
@@ -26,3 +39,2 @@ const resInfo = { | ||
const stream = require('stream') | ||
const util = require('util') | ||
if (resInfo.data instanceof stream.Readable) { | ||
@@ -29,0 +41,0 @@ resInfo.data[util.inspect.custom] = function (depth, options) { |
{ | ||
"name": "lws-request-monitor", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Verbose request logging middleware for lws", | ||
@@ -19,3 +19,6 @@ "repository": "https://github.com/lwsjs/request-monitor.git", | ||
"test-runner-counter": "^0.1.1" | ||
}, | ||
"dependencies": { | ||
"byte-size": "^4.0.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21479
63
1
+ Addedbyte-size@^4.0.1
+ Addedbyte-size@4.0.4(transitive)