Files
dashboardAPI/dashboardAPI.js

46 lines
1.6 KiB
JavaScript
Raw Normal View History

2026-01-13 14:29:43 +01:00
const fs = require('node:fs');
const path = require('node:path');
const nameOfNode = 'dashboardapi';
const nodeClass = require('./src/nodeClass.js');
const { MenuManager } = require('generalFunctions');
2025-05-26 17:44:56 +02:00
module.exports = function (RED) {
2026-01-13 14:29:43 +01:00
RED.nodes.registerType(nameOfNode, function (config) {
2025-05-26 17:44:56 +02:00
RED.nodes.createNode(this, config);
2026-01-13 14:29:43 +01:00
this.nodeClass = new nodeClass(config, RED, this, nameOfNode);
}, {
credentials: {
bearerToken: { type: 'password' },
},
2026-01-13 14:29:43 +01:00
});
2025-05-26 17:44:56 +02:00
2026-01-13 14:29:43 +01:00
const menuMgr = new MenuManager();
2025-05-26 17:44:56 +02:00
2026-01-13 14:29:43 +01:00
RED.httpAdmin.get(`/${nameOfNode}/menu.js`, (req, res) => {
2025-05-26 17:44:56 +02:00
try {
2026-01-13 14:29:43 +01:00
const script = menuMgr.createEndpoint(nameOfNode, ['logger']);
res.type('application/javascript').send(script);
} catch (err) {
res.status(500).send(`// Error generating menu: ${err.message}`);
2025-05-26 17:44:56 +02:00
}
2026-01-13 14:29:43 +01:00
});
2025-05-26 17:44:56 +02:00
2026-01-13 14:29:43 +01:00
// Provide config metadata for the editor (local, no dependency on generalFunctions configs).
RED.httpAdmin.get(`/${nameOfNode}/configData.js`, (req, res) => {
try {
const configPath = path.join(__dirname, 'dependencies', 'dashboardapi', 'dashboardapiConfig.json');
const json = JSON.parse(fs.readFileSync(configPath, 'utf8'));
const script = `
window.EVOLV = window.EVOLV || {};
window.EVOLV.nodes = window.EVOLV.nodes || {};
window.EVOLV.nodes.${nameOfNode} = window.EVOLV.nodes.${nameOfNode} || {};
window.EVOLV.nodes.${nameOfNode}.config = ${JSON.stringify(json, null, 2)};
`;
res.type('application/javascript').send(script);
} catch (err) {
res.status(500).send(`// Error generating configData: ${err.message}`);
}
});
2025-05-26 17:44:56 +02:00
};