From 702d41f7da24ec965edd815fc259990df181ba39 Mon Sep 17 00:00:00 2001 From: Harold Hunt Date: Sat, 15 Mar 2025 17:36:12 -0400 Subject: [PATCH] Disable demo-app logs by default skip-checks:true --- package.json | 1 + src/demo-app/app.cjs | 14 +++++++++----- src/demo-app/package.json | 1 + 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index ab342720..ee1bb2f7 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "build": "tsc --build tsconfig.json", "build:demo-app": "yarn workspace @pwrdrvr/lambda-dispatch-demo-app build", "start:demo-app": "NUMBER_OF_WORKERS=${NUMBER_OF_WORKERS:-1} yarn workspace @pwrdrvr/lambda-dispatch-demo-app start:app", + "start:demo-app:logging": "NUMBER_OF_WORKERS=${NUMBER_OF_WORKERS:-1} yarn workspace @pwrdrvr/lambda-dispatch-demo-app start:app:logging", "test": "yarn workspace @pwrdrvr/lambda-dispatch-cdk test && yarn workspace @pwrdrvr/lambda-dispatch-cdk-stack test" }, "author": "", diff --git a/src/demo-app/app.cjs b/src/demo-app/app.cjs index 2e51b47b..6def8368 100644 --- a/src/demo-app/app.cjs +++ b/src/demo-app/app.cjs @@ -62,7 +62,9 @@ const logFormat = // Use the custom format app.use(trackBytes); -app.use(morgan(logFormat)); +if (process.env.LOGGING === 'true') { + app.use(morgan(logFormat)); +} const port = 3001; const spdyPort = 3002; @@ -371,7 +373,9 @@ app.post('/echo', async (req, res) => { const timestamp = new Date().toISOString(); totalBytesReceived += chunk.length; if (debugMode) { - console.log(`${logPrefix} - RECEIVED chunk ${chunk.length} bytes, total ${totalBytesReceived} bytes at ${timestamp}`); + console.log( + `${logPrefix} - RECEIVED chunk ${chunk.length} bytes, total ${totalBytesReceived} bytes at ${timestamp}`, + ); } this.push(chunk); @@ -383,7 +387,7 @@ app.post('/echo', async (req, res) => { console.log(`${logPrefix} - FINISHED`); } callback(); - } + }, }); // Pipe the req body to the response with back pressure @@ -465,7 +469,7 @@ app.post('/double-echo', async (req, res) => { app.post('/half-echo', async (req, res) => { const contentType = req.get('Content-Type'); - + if (contentType) { res.set('Content-Type', contentType); } @@ -492,7 +496,7 @@ app.post('/half-echo', async (req, res) => { const halfLength = chunk.length >> 1; this.push(chunk.slice(0, halfLength), 'binary'); callback(); - } + }, }); // Pipe through halver transform then to response diff --git a/src/demo-app/package.json b/src/demo-app/package.json index 3582a68f..501b8091 100644 --- a/src/demo-app/package.json +++ b/src/demo-app/package.json @@ -10,6 +10,7 @@ "build:directlambda": "esbuild directlambda.mjs --bundle --platform=node --format=esm --external:./serverlessloader.cjs --outfile=dist/directlambda.mjs", "build:serverlessloader": "esbuild serverlessloader.cjs --bundle --platform=node --format=cjs --outfile=dist/serverlessloader.cjs", "start:app": "node dist/app.cjs", + "start:app:logging": "LOGGING=true node dist/app.cjs", "start:directlambda": "node dist/directlambda.mjs" }, "author": "PwrDrvr LLC",