/** * Node-RED 5.0 settings for s2s-reasoning-engine — LOCAL INSTALL (non Docker). * File: /s2s-reasoning-engine/.node-red/settings.js * oppure /s2s-reasoning-engine/settings.js (master) * * Copiato automaticamente in .node-red/ da start.sh se mancante o più vecchio. */ const path = require("path"); const fs = require("fs"); // userDir è sempre /.node-red (lo script start.sh) const ENGINE_ROOT = path.resolve(__dirname, ".."); const LOCAL_NODE_MODULES = path.join(ENGINE_ROOT, "node_modules"); const USERDIR_NODE_MODULES = path.join(__dirname, "node_modules"); // ── Fix per editor "tslib.es6.js 404 / net::ERR_ABORTED" ───────────────── // Installazioni npm locali flat (default npm 3+) spostano tslib in // node_modules/tslib/ (root) invece che dentro // @node-red/editor-client/node_modules/tslib/. L'editor di Node-RED 5 // carica `/tslib.es6.js` dalla root HTTP: se la cartella nested non esiste, // torna 404. Qui aggiorniamo editor-client/public/ con i file tslib mancanti // a ogni avvio (sopravvive a npm reinstall se tslib è in root). (function _installTslibVendor() { try { const tslibRoot = path.join(LOCAL_NODE_MODULES, "tslib"); if (!fs.existsSync(path.join(tslibRoot, "tslib.es6.js"))) return; const pub = path.join(LOCAL_NODE_MODULES, "@node-red", "editor-client", "public"); if (!fs.existsSync(pub)) return; for (const f of ["tslib.es6.js", "tslib.js", "tslib.mjs"]) { const src = path.join(tslibRoot, f); const dst = path.join(pub, f); if (!fs.existsSync(src)) continue; try { const s = fs.statSync(src); const d = fs.existsSync(dst) ? fs.statSync(dst) : null; if (!d || d.size !== s.size || d.mtimeMs < s.mtimeMs) { fs.copyFileSync(src, dst); } } catch (e) { /* ignore */ } } } catch (e) { /* no-op */ } })(); module.exports = { uiPort: process.env.PORT || process.env.NODE_RED_PORT || 1881, uiHost: "0.0.0.0", httpRequestTimeout: 120000, httpRequestLegacyMsgOverrides: true, // ── Native HTTP helper per function node (SENZA externalModules) ───── // NOTA: non usare functionExternalModules: true — in Node-RED v5 quel // flag può bloccare il caricamento palette (es. "37/41 nodes loading" // durante la verifica di tutti i pkg npm). // Al suo posto usiamo functionGlobalContext: i moduli core Node.js sono // require'd QUI nel settings.js (prima dell'avvio NR) e poi i function // node li recuperano via global.get("_core_https") ecc. functionModuleRequireAllowList: ["https","http","url","path","util","fs","os","buffer","zlib","stream","crypto"], functionGlobalContext: { _core_https: require("https"), _core_http: require("http"), _core_url: require("url"), }, // adminAuth: {...} ← scommentare e valorizzare in produzione // HTTPS (opzionale in produzione) // https: { // key: require("fs").readFileSync(path.join(__dirname, "privkey.pem")), // cert: require("fs").readFileSync(path.join(__dirname, "fullchain.pem")) // }, flowFile: process.env.FLOWS || path.join(__dirname, "flows.json"), flowFilePretty: true, credentialSecret: process.env.NODE_RED_CREDENTIAL_SECRET || "s2s-reasoning-local-dev", httpNodeCors: { origin: "*", methods: "GET,PUT,POST,DELETE,OPTIONS", credentials: true, }, csrf: false, // ── IMPORTANTE: caricamento nodi extra ───────────────────────────── // Node-RED 5 carica i plugin NODI da: // 1) {userDir}/node_modules (nostro .node-red/node_modules) // 2) {nodesDir} (installazione root del progetto) // 3) npm global // Senza nodesDir i pacchetti installati nella ROOT del progetto non // vengono trovati. nodesDir: LOCAL_NODE_MODULES, externalModules: { autoInstall: true, // auto-installa nodi mancanti al boot autoInstallRetry: 3, palette: { allowInstall: true, // permette Install dall'editor allowUpload: true, modules: ["node-red-contrib-openai", "node-red-contrib-cache", "node-red-node-rbe"], allowList: ["node-red-contrib-*", "node-red-node-*"], denyList: [] } }, editorTheme: { projects: { enabled: false } }, logging: { console: { level: process.env.NODE_RED_LOG_LEVEL || process.env.LOG_LEVEL || "info", metrics: false, audit: false, timestamp: true, } }, contextStorage: { default: { module: "memory" }, file: { module: "localfilesystem" } }, };