47 lines
1.6 KiB
JavaScript
47 lines
1.6 KiB
JavaScript
/**
|
|
* Thin wrapper that registers a node with Node-RED and exposes HTTP endpoints. and loads EVOLV in a standard way
|
|
*/
|
|
|
|
const nodeClass = require('./src/nodeClass.js');
|
|
const { MenuManager, configManager } = require('generalFunctions');
|
|
const nameOfNode = 'measurement';
|
|
|
|
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);
|
|
});
|
|
|
|
// Setup admin UIs
|
|
const menuMgr = new MenuManager();
|
|
const cfgMgr = new configManager();
|
|
|
|
console.log(`Loading endpoint for ${nameOfNode} menu...`);
|
|
// Register the menu for the measurement node
|
|
RED.httpAdmin.get('/measurement/menu.js', (req, res) => {
|
|
try {
|
|
const script = menuMgr.createEndpoint(nameOfNode, ['asset']);
|
|
res.type('application/javascript').send(script);
|
|
} catch (err) {
|
|
res.status(500).send(`// Error generating menu: ${err.message}`);
|
|
}
|
|
});
|
|
|
|
console.log(`Loading endpoint for ${nameOfNode} config...`);
|
|
// Endpoint to get the configuration data for the measurement node
|
|
RED.httpAdmin.get(`/measurement/configData.js`, (req, res) => {
|
|
try {
|
|
const script = cfgMgr.createEndpoint(nameOfNode);
|
|
// Send the configuration data as JSON response
|
|
res.type('application/javascript').send(script);
|
|
} catch (err) {
|
|
res.status(500).send(`// Error generating configData: ${err.message}`);
|
|
}
|
|
});
|
|
|
|
console.log(`Measurement node '${nameOfNode}' registered.`);
|
|
}; |