26 lines
924 B
JavaScript
26 lines
924 B
JavaScript
const nameOfNode = "settler"; // name of the node, should match file name and node type in Node-RED
|
|
const nodeClass = require('./src/nodeClass.js'); // node class
|
|
const { MenuManager } = require('generalFunctions');
|
|
|
|
|
|
module.exports = function (RED) {
|
|
// Register the node type
|
|
RED.nodes.registerType(nameOfNode, function (config) {
|
|
// Initialize the Node-RED node first
|
|
RED.nodes.createNode(this, config);
|
|
// Then create your custom class and attach it
|
|
this.nodeClass = new nodeClass(config, RED, this, nameOfNode);
|
|
});
|
|
|
|
const menuMgr = new MenuManager();
|
|
|
|
// Serve /settler/menu.js
|
|
RED.httpAdmin.get(`/${nameOfNode}/menu.js`, (req, res) => {
|
|
try {
|
|
const script = menuMgr.createEndpoint(nameOfNode, ['logger', 'position']);
|
|
res.type('application/javascript').send(script);
|
|
} catch (err) {
|
|
res.status(500).send(`// Error generating menu: ${err.message}`);
|
|
}
|
|
});
|
|
}; |