diff --git a/server/node/error.js b/server/node/error.js index cdd69fd7..c7990a79 100644 --- a/server/node/error.js +++ b/server/node/error.js @@ -22,7 +22,7 @@ function throwFatalErrorIfFallback(res, condition, title, description, details=" res.end(); return; } - //try to add additional info to the file + console.error(`${title}: ${description}`); const replacer = function(match, p1) { switch (p1) { @@ -64,6 +64,7 @@ function showError(res, errTitle, errDesc, errDetails, locale='en') { return throwFatalErrorIfFallback(res, true, errTitle, errDesc, errDetails); } + console.error(`${title}: ${description}`); const replacer = function(match, p1) { switch (p1) { diff --git a/server/node/index.js b/server/node/index.js index 41d25722..7bdde4de 100644 --- a/server/node/index.js +++ b/server/node/index.js @@ -40,7 +40,7 @@ const initViewerCoreAndPlugins = (req, res) => { path => fs.readFileSync(path, { encoding: 'utf8', flag: 'r' }), key => process.env[key]); - if (throwFatalErrorIf(res, core.exception, "Failed to parse the CORE initialization!")) return null; + if (throwFatalErrorIf(res, core.exception, "Failed to parse the CORE initialization!", core.exception)) return null; core.CORE.serverStatus.name = "node"; core.CORE.serverStatus.supportsPost = true; @@ -50,7 +50,7 @@ const initViewerCoreAndPlugins = (req, res) => { path => fs.readFileSync(path, { encoding: 'utf8', flag: 'r' }), dirName => fs.readdirSync(dirName).filter(f => fs.statSync(dirName + '/' + f).isDirectory()), { t: function () { return "Unknown Error (e-translate)."; } }); - if (throwFatalErrorIf(res, core.exception, "Failed to parse the MODULES or PLUGINS initialization!")) return null; + if (throwFatalErrorIf(res, core.exception, "Failed to parse the MODULES or PLUGINS initialization!", core.exception)) return null; return core; } @@ -144,7 +144,6 @@ async function responseViewer(req, res) { const core = initViewerCoreAndPlugins(req, res); if (!core) return; - const replacer = function(match, p1) { try { switch (p1) { @@ -208,7 +207,11 @@ async function responseDeveloperSetup(req, res) { const core = initViewerCoreAndPlugins(req, res); if (!core) return; - core.MODULES["webgl"].loaded = true; + if (core.MODULES["webgl"]) { + core.MODULES["webgl"].loaded = true; + } else { + console.warn("Could not find webgl module: visualizations will not work!"); + } const replacer = function (match, p1) { try { switch (p1) { @@ -281,7 +284,7 @@ server.listen(process.env.XOPAT_NODE_PORT || 9000, '0.0.0.0', () => { console.log("Using env/env.json.."); } else if (ENV) { if (fs.existsSync(ENV)) console.log("Using static ENV from ", ENV); - else console.log("Using static ENV directly from the variable data: ", ENV.substring(0, 31) + "..."); + else console.log("Using configuration from XOPAT_ENV: ", ENV.substring(0, 31) + "..."); } else { console.log("Using default ENV (no overrides)."); } diff --git a/server/templates/javascript/modules.js b/server/templates/javascript/modules.js index c8e70809..2e49e7f8 100644 --- a/server/templates/javascript/modules.js +++ b/server/templates/javascript/modules.js @@ -1,4 +1,5 @@ const {parse} = require("comment-json"); +const {safeScanDir} = require("./utils"); module.exports.loadModules = function(core, fileExists, readFile, scanDir, i18n) { @@ -6,7 +7,7 @@ module.exports.loadModules = function(core, fileExists, readFile, scanDir, i18n) const MODULES = core.MODULES, ENV = core.ENV; - let modulePaths = scanDir(core.ABS_MODULES); + let modulePaths = safeScanDir(core.ABS_MODULES); for (let dir of modulePaths) { if (dir == "." || dir == "..") continue; @@ -55,10 +56,8 @@ module.exports.loadModules = function(core, fileExists, readFile, scanDir, i18n) console.error(core.exception, e); } } - } - let order = 0; //DFS assigns smaller numbers to children -> loaded earlier diff --git a/server/templates/javascript/plugins.js b/server/templates/javascript/plugins.js index 79cfc728..edcf2fb3 100644 --- a/server/templates/javascript/plugins.js +++ b/server/templates/javascript/plugins.js @@ -1,5 +1,6 @@ const {parse} = require("comment-json") const {loadModules} = require("./modules"); +const {safeScanDir} = require("./utils"); module.exports.loadPlugins = function(core, fileExists, readFile, scanDir, i18n) { @@ -19,7 +20,7 @@ module.exports.loadPlugins = function(core, fileExists, readFile, scanDir, i18n) MODULES = core.MODULES, ENV = core.ENV; - let pluginPaths = scanDir(core.ABS_PLUGINS); + let pluginPaths = safeScanDir(core.ABS_PLUGINS); for (let dir of pluginPaths) { if (dir == "." || dir == "..") continue; diff --git a/server/templates/javascript/utils.js b/server/templates/javascript/utils.js new file mode 100644 index 00000000..b59224f1 --- /dev/null +++ b/server/templates/javascript/utils.js @@ -0,0 +1,24 @@ +const fs = require("fs"); +const path = require("path"); + +module.exports.safeScanDir = function (directory) { + let resolvedPaths = []; + try { + const entries = fs.readdirSync(directory); + + resolvedPaths = entries.map((entry) => { + const fullPath = path.join(directory, entry); + try { + const realPath = fs.realpathSync(fullPath); + fs.statSync(realPath); + return entry; + } catch (err) { + console.error(`Failed to resolve or stat: ${fullPath}`, err.message); + return null; + } + }); + } catch (err) { + console.error(`Error scanning directory: ${directory}`, err.message); + } + return resolvedPaths.filter(Boolean); +}