Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@compas/server

Package Overview
Dependencies
Maintainers
1
Versions
196
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@compas/server - npm Package Compare versions

Comparing version 0.0.107 to 0.0.108

10

index.d.ts

@@ -1307,2 +1307,12 @@ // Original types from @types/koa & @types/koa-compose

headers?: HeaderOptions;
/**
* Options passed to the log middleware
*/
logOptions?: {
/**
* Disable event creation on ctx.event
*/
disableRootEvent?: boolean;
};
}

@@ -1309,0 +1319,0 @@

10

package.json
{
"name": "@compas/server",
"version": "0.0.107",
"version": "0.0.108",
"description": "Koa server and common middleware",

@@ -18,7 +18,7 @@ "main": "./index.js",

"dependencies": {
"@compas/insight": "0.0.107",
"@compas/stdlib": "0.0.107",
"@compas/insight": "0.0.108",
"@compas/stdlib": "0.0.108",
"formidable": "2.0.0-canary.20200504.1",
"keygrip": "1.1.0",
"koa": "2.13.0",
"koa": "2.13.1",
"koa-body": "4.2.0",

@@ -48,3 +48,3 @@ "koa-session": "6.1.0"

},
"gitHead": "3788c6771ecb63aa83528f821c0572b22b524d3d"
"gitHead": "83367f8c39df9f42ff1669b8be6d19fc14c0c5e6"
}

@@ -22,3 +22,3 @@ import { isProduction } from "@compas/stdlib";

app.use(logMiddleware());
app.use(logMiddleware(opts.logOptions ?? {}));
app.use(errorHandler(opts.errorOptions || {}));

@@ -25,0 +25,0 @@ app.use(notFoundHandler());

@@ -7,4 +7,37 @@ import { Transform } from "stream";

* Log basic request and response information
* @param {GetAppOptions.logOptions} options
*/
export function logMiddleware() {
export function logMiddleware(options) {
/**
* Real log function
*
* @param ctx
* @param {bigint} startTime
* @param {number} length
*/
function logInfo(ctx, startTime, length) {
const duration = Math.round(
Number(process.hrtime.bigint() - startTime) / 1000000,
);
ctx.log.info({
request: {
method: ctx.method,
path: ctx.path,
length: Number(ctx.get("Content-Length") || "0"),
},
response: {
duration,
length,
status: ctx.status,
},
});
// Skip eventStop if we don't have events enabled.
// Skip eventStop for CORS requests, this gives a bit cleaner logs.
if (options.disableRootEvent !== true && ctx.method !== "OPTIONS") {
eventStop(ctx.event);
}
}
return async (ctx, next) => {

@@ -25,5 +58,8 @@ const startTime = process.hrtime.bigint();

});
ctx.event = newEvent(ctx.log);
eventStart(ctx.event, `${ctx.method}.${ctx.path}`);
if (options.disableRootEvent !== true) {
ctx.event = newEvent(ctx.log);
eventStart(ctx.event, `${ctx.method}.${ctx.path}`);
}
await next();

@@ -63,32 +99,2 @@

/**
* Real log function
*
* @param ctx
* @param {bigint} startTime
* @param {number} length
*/
function logInfo(ctx, startTime, length) {
const duration = Math.round(
Number(process.hrtime.bigint() - startTime) / 1000000,
);
ctx.log.info({
request: {
method: ctx.method,
path: ctx.path,
length: Number(ctx.get("Content-Length") || "0"),
},
response: {
duration,
length,
status: ctx.status,
},
});
if (ctx.method !== "OPTIONS") {
eventStop(ctx.event);
}
}
/**
* Wait for the ctx.body stream to finish before resolving

@@ -95,0 +101,0 @@ *

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc