@lbu/server
Advanced tools
Comparing version 0.0.9 to 0.0.10
@@ -10,3 +10,3 @@ import compose from "koa-compose"; | ||
AppError, | ||
logParser, | ||
isServerLog, | ||
} from "./src/middleware/index.js"; |
{ | ||
"name": "@lbu/server", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"description": "Koa server and common middleware", | ||
"main": "index.js", | ||
"main": "./index.js", | ||
"exports": "./index.js", | ||
"type": "module", | ||
@@ -17,4 +18,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@lbu/insight": "^0.0.9", | ||
"@lbu/stdlib": "^0.0.9", | ||
"@lbu/insight": "^0.0.10", | ||
"@lbu/stdlib": "^0.0.10", | ||
"koa": "2.11.0", | ||
@@ -36,5 +37,5 @@ "koa-body": "4.1.1", | ||
"engines": { | ||
"node": ">=12" | ||
"node": ">=14" | ||
}, | ||
"gitHead": "d847630e049071c7c2385eef8377ba976ddd0e2a" | ||
"gitHead": "35e227dd5217c7eda76fcc69adaabb19207e3008" | ||
} |
@@ -21,3 +21,3 @@ # @lbu/server | ||
- Various utilities like loading .env files, executing other processes and a | ||
basic template system | ||
basic string templating system | ||
@@ -24,0 +24,0 @@ ## Docs |
@@ -9,3 +9,3 @@ export { | ||
export { healthHandler } from "./health.js"; | ||
export { logMiddleware, logParser } from "./log.js"; | ||
export { logMiddleware, isServerLog } from "./log.js"; | ||
export { notFoundHandler } from "./notFound.js"; |
@@ -21,3 +21,3 @@ import { newLogger } from "@lbu/insight"; | ||
ctx: { | ||
type: "HTTP", | ||
type: "http", | ||
requestId, | ||
@@ -45,23 +45,16 @@ }, | ||
/** | ||
* Basic http log counters | ||
* @param store | ||
* @return {function(...[*]=)} | ||
* Given a logged object, check if it is a request log | ||
* @param {object} obj | ||
* @return {boolean} | ||
*/ | ||
export function logParser(store) { | ||
store.requestCount = 0; | ||
store.totalDuration = 0; | ||
store.totalResponseLength = 0; | ||
store.methodSummary = {}; | ||
store.statusCodeSummary = {}; | ||
export function isServerLog(obj) { | ||
if (!obj.type || obj.type !== "http") { | ||
return false; | ||
} | ||
return (obj) => { | ||
if (!obj.type || obj.type !== "HTTP") { | ||
return; | ||
} | ||
if (!obj.message || !obj.message.request || !obj.message.response) { | ||
return; | ||
} | ||
if (!obj.message || (!obj.message.request && !obj.message.response)) { | ||
return false; | ||
} | ||
handleRequestLog(store, obj); | ||
}; | ||
return obj.message.request.path && !!obj.message.response.duration; | ||
} | ||
@@ -98,3 +91,2 @@ | ||
request: { | ||
ip: ctx.ip, | ||
method: ctx.method, | ||
@@ -111,18 +103,2 @@ path: ctx.path, | ||
function handleRequestLog(store, obj) { | ||
store.requestCount++; | ||
store.totalDuration += Number(obj.message.response.duration); | ||
store.totalResponseLength += obj.message.response.length; | ||
if (!store.methodSummary[obj.message.request.method]) { | ||
store.methodSummary[obj.message.request.method] = 0; | ||
} | ||
store.methodSummary[obj.message.request.method]++; | ||
if (!store.statusCodeSummary[obj.message.response.status]) { | ||
store.statusCodeSummary[obj.message.response.status] = 0; | ||
} | ||
store.statusCodeSummary[obj.message.response.status]++; | ||
} | ||
/** | ||
@@ -129,0 +105,0 @@ * Wait for the ctx.body stream to finish before resolving |
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
18358
506
+ Added@lbu/insight@0.0.10(transitive)
+ Added@lbu/stdlib@0.0.10(transitive)
+ Addeduuid@7.0.3(transitive)
- Removed@lbu/insight@0.0.9(transitive)
- Removed@lbu/stdlib@0.0.9(transitive)
- Removeduuid@7.0.2(transitive)
Updated@lbu/insight@^0.0.10
Updated@lbu/stdlib@^0.0.10