From 881502d8979d7d86e3dbe3891088da9abe39a756 Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Fri, 23 Aug 2024 21:58:26 +0200 Subject: [PATCH] Disable console.log for non-TTY stdout --- src/index.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/index.js b/src/index.js index 562b672..b7c8ae0 100644 --- a/src/index.js +++ b/src/index.js @@ -8,6 +8,13 @@ const version = svrjsInfo.version; //const parseURL = require("./utils/urlParser.js"); //const fixNodeMojibakeURL = require("./utils/urlMojibakeFixer.js"); +let inspector = undefined; +try { + inspector = require("inspector"); +} catch (err) { + // Don't use inspector +} + // Create log, mods and temp directories, if they don't exist. if (!fs.existsSync(__dirname + "/log")) fs.mkdirSync(__dirname + "/log"); if (!fs.existsSync(__dirname + "/mods")) fs.mkdirSync(__dirname + "/mods"); @@ -15,6 +22,23 @@ if (!fs.existsSync(__dirname + "/temp")) fs.mkdirSync(__dirname + "/temp"); const serverconsoleConstructor = require("./utils/serverconsole.js"); +let inspectorURL = undefined; +try { + if (inspector) { + inspectorURL = inspector.url(); + } +} catch (err) { + // Failed to get inspector URL +} + +if (!process.stdout.isTTY && !inspectorURL) { + // When stdout is not a terminal and not attached to an Node.JS inspector, disable it to improve performance of SVR.JS + console.log = function () {}; + process.stdout.write = function () {}; + process.stdout._write = function () {}; + process.stdout._writev = function () {}; +} + let configJSON = {}; // TODO: configuration from config.json