You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flagon.apache.org by ej...@apache.org on 2024/07/30 20:49:40 UTC

(flagon-useralejs) branch karapace-router updated: feat(example): fix karapace-router logging

This is an automated email from the ASF dual-hosted git repository.

ejones pushed a commit to branch karapace-router
in repository https://gitbox.apache.org/repos/asf/flagon-useralejs.git


The following commit(s) were added to refs/heads/karapace-router by this push:
     new fcc923f  feat(example): fix karapace-router logging
fcc923f is described below

commit fcc923f628bf4cc00ad360d67b43119a94da49cd
Author: Evan Jones <ev...@gmail.com>
AuthorDate: Tue Jul 30 16:43:29 2024 -0400

    feat(example): fix karapace-router logging
---
 example/karapace-router.js | 21 ++++++++++++---------
 package.json               |  2 +-
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/example/karapace-router.js b/example/karapace-router.js
index 835616b..aac788e 100644
--- a/example/karapace-router.js
+++ b/example/karapace-router.js
@@ -17,20 +17,20 @@
  * under the License.
  */
 
-const commander = require('commander');
-const { program } = require('commander');
-const express  = require('express');
-const bodyParser  =  require('body-parser');
+const commander = require("commander");
+const { program } = require("commander");
+const express = require("express");
+const bodyParser = require("body-parser");
 
 // Functions.
-const myParseInt = (value, _dummyPrevious) =>  {
+const myParseInt = (value, _dummyPrevious) => {
   // parseInt takes a string and a radix
   const parsedValue = parseInt(value, 10);
   if (isNaN(parsedValue)) {
-    throw new commander.InvalidArgumentError('Not a number.');
+    throw new commander.InvalidArgumentError("Not a number.");
   }
   return parsedValue;
-}
+};
 
 const configureCors = (req, res, next) => {
   res.header("Access-Control-Allow-Origin", "*");
@@ -60,14 +60,17 @@ const transformAndForward = async (req, res) => {
       Object.keys(body).length === 0;
     if (isEmptyArray || isEmptyObject) return;
 
+    if (options.verbose) console.log(JSON.stringify(body, null, 3));
+
     const transformedPayload = {
-      records: body.forEach((log) => ({
+      records: body.map((log) => ({
         key: log["sessionId"],
         value: log,
       })),
     };
 
-    if (options.verbose) console.log(transformedPayload);
+    if (options.verbose)
+      console.log(JSON.stringify(transformedPayload, null, 3));
 
     const response = await fetch(options.forwardTo, {
       method: "POST",
diff --git a/package.json b/package.json
index 1657233..d53742e 100644
--- a/package.json
+++ b/package.json
@@ -15,7 +15,7 @@
     "clean": "rm -rf ./build",
     "test": "npm run test:unit && npm run test:e2e",
     "test:unit": "jest -c ./test/unit/jest.config.ts",
-    "test:e2e": "xvfb-run playwright test -c ./test/e2e/playwright.config.ts",
+    "test:e2e": "playwright test -c ./test/e2e/playwright.config.ts",
     "pretest:e2e": "rm -rf ./test/e2e/chromeData/*",
     "posttest:e2e": "rm -rf ./test/e2e/chromeData/*",
     "example:run": "node example/server.js",