@compas/server
Advanced tools
Comparing version 0.0.166 to 0.0.167
{ | ||
"name": "@compas/server", | ||
"version": "0.0.166", | ||
"version": "0.0.167", | ||
"description": "Koa server and common middleware", | ||
@@ -18,3 +18,3 @@ "main": "./index.js", | ||
"dependencies": { | ||
"@compas/stdlib": "0.0.166", | ||
"@compas/stdlib": "0.0.167", | ||
"@types/formidable": "1.2.4", | ||
@@ -21,0 +21,0 @@ "@types/koa": "2.13.4", |
@@ -85,3 +85,3 @@ import { isProduction } from "@compas/stdlib"; | ||
app.use(logMiddleware(opts.logOptions ?? {})); | ||
app.use(logMiddleware(app, opts.logOptions ?? {})); | ||
app.use(errorHandler(opts.errorOptions ?? {})); | ||
@@ -88,0 +88,0 @@ app.use(notFoundHandler()); |
/** | ||
* Log basic request and response information | ||
* | ||
* @param {import("koa")} app | ||
* @param {{ disableRootEvent?: boolean }} options | ||
*/ | ||
export function logMiddleware(options: { | ||
export function logMiddleware(app: import("koa"), options: { | ||
disableRootEvent?: boolean; | ||
}): (ctx: any, next: any) => Promise<void>; | ||
//# sourceMappingURL=log.d.ts.map |
import { Transform } from "stream"; | ||
import { | ||
AppError, | ||
eventStart, | ||
@@ -14,5 +15,6 @@ eventStop, | ||
* | ||
* @param {import("koa")} app | ||
* @param {{ disableRootEvent?: boolean }} options | ||
*/ | ||
export function logMiddleware(options) { | ||
export function logMiddleware(app, options) { | ||
/** | ||
@@ -50,2 +52,17 @@ * Real log function | ||
// Log stream errors after the headers are sent | ||
const logger = newLogger({ | ||
ctx: { | ||
type: "http-error", | ||
}, | ||
}); | ||
app.on("error", (error, ctx) => { | ||
(ctx?.log ?? logger).info({ | ||
type: "http-error", | ||
headerSent: error.headerSent, | ||
syscall: error.syscall, | ||
error: AppError.format(error), | ||
}); | ||
}); | ||
return async (ctx, next) => { | ||
@@ -52,0 +69,0 @@ const startTime = process.hrtime.bigint(); |
@@ -64,2 +64,3 @@ import { isNil } from "@compas/stdlib"; | ||
if (isNil(start) || start > file.contentLength) { | ||
// '-500' results in the last 500 bytes send | ||
start = file.contentLength - end; | ||
@@ -66,0 +67,0 @@ end = file.contentLength - 1; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
48669
1256
+ Added@compas/stdlib@0.0.167(transitive)
- Removed@compas/stdlib@0.0.166(transitive)
Updated@compas/stdlib@0.0.167