Skip to content

Commit

Permalink
feat(example): fix karapace-router logging
Browse files Browse the repository at this point in the history
  • Loading branch information
EandrewJones committed Jul 30, 2024
1 parent 38d3c37 commit fcc923f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions example/karapace-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", "*");
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit fcc923f

Please sign in to comment.