diff --git a/app.js b/app.js index 74249fb..5710b35 100644 --- a/app.js +++ b/app.js @@ -74,16 +74,25 @@ router.get('/topics/:cluster', async (req, res, _next) => { } }) +const buildSocketMessageSender = ({ type, socket }) => message => { + socket.send(JSON.stringify({ + type, + message + })) +} + +const deepCopy = object => JSON.parse(JSON.stringify(object)) + const passwordPlaceholder = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX' const getClusterData = () => Object.fromEntries( - Object.entries(clusters).map(([key, value]) => { - value = JSON.parse(JSON.stringify(value)) - if (value.config.sasl?.password) { - value.config.sasl.password = passwordPlaceholder + Object.entries(clusters).map(([key, cluster]) => { + cluster = deepCopy(cluster) + if (cluster.config.sasl?.password) { + cluster.config.sasl.password = passwordPlaceholder } - return [key, value.config] + return [key, cluster.config] })) router.get('/clusters', async (req, res, _next) => { @@ -132,13 +141,6 @@ router.put('/clusters', async (req, res, _next) => { app.use(router) -const buildSocketMessageSender = ({ type, socket }) => message => { - socket.send(JSON.stringify({ - type, - message - })) -} - const realTimeSearch = async ({ kafka, socket, topic }) => query.realTimeMessageSearch({ kafka, diff --git a/config.js b/config.js index e8b5090..5a71012 100644 --- a/config.js +++ b/config.js @@ -2,7 +2,7 @@ const fs = require('fs') const path = require('path') const homedir = require('os').homedir() -const configFilePath = homedir + path.sep + '.kafka-dance' +const configFilePath = homedir + path.sep + '.kafka-dance.json' const emptyConfig = () => ({ clusters: {},