From ae9726f747b2ec3e5805d03ef04ad47cb7628315 Mon Sep 17 00:00:00 2001 From: kaotisk Date: Mon, 10 Jun 2024 05:08:59 +0300 Subject: Refactoring --- api/routes/getNodeInfo/index.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'api/routes/getNodeInfo/index.js') diff --git a/api/routes/getNodeInfo/index.js b/api/routes/getNodeInfo/index.js index 877b55a..d99382a 100644 --- a/api/routes/getNodeInfo/index.js +++ b/api/routes/getNodeInfo/index.js @@ -2,7 +2,7 @@ const { spawn } = require('child_process'); const akLogMessage = require('../../lib/akLogMessage'); module.exports = (req, res) => { - akLogMessage('INFO', `Incoming from [${req.socket._peername.address}]:${req.socket._peername.port} @ ${req.get('host')}${req._parsedOriginalUrl.pathname}`); + akLogMessage('INFO', `Incoming from [${req.connection.remoteAddress}]:${req.socket._peername.port} @ ${req.url}`); const command = spawn("ak-config", ["--get-published"]); var buffer = ""; command.stdout.on("data", data => { @@ -10,15 +10,16 @@ module.exports = (req, res) => { }); command.stderr.on("data", data => { - console.log(`stderr: ${data}`); + console.log(`stderr: ${data}`); }); command.on('error', (error) => { - console.log(`error: ${error.message}`); + console.log(`error: ${error.message}`); }); command.on("close", code => { - res.send(JSON.parse(buffer)); - console.log(`child process exited with code ${code}`); + res.writeHead(200, { 'Content-Type': 'application/json'}); + res.end(buffer); + console.log(`child process exited with code ${code}`); }); }; -- cgit v1.2.3