Hi,
I am trying to embed the node-red app into an existing app using this doc.
I have created a file according to the official doc. Now I want to inject a flow and see its dashboard.
var http = require('http');
var express = require("express");
var RED = require("node-red");
var flows = [{ "id": "2e7b0abc.b895c6", "type": "tab", "label": "Flow 1", "disabled": false, "info": "" }, { "id": "3cb312e1.19870e", "type": "inject", "z": "2e7b0abc.b895c6", "name": "", "topic": "", "payload": "", "payloadType": "date", "repeat": "1", "crontab": "", "once": true, "onceDelay": 0.1, "x": 150, "y": 160, "wires": [["d34dca7a.9d33f8"]] }, { "id": "592badab.9a40f4", "type": "ui_chart", "z": "2e7b0abc.b895c6", "name": "", "group": "99cb9d74.9e3e1", "order": 1, "width": 11, "height": 6, "label": "chart", "chartType": "line", "legend": "false", "xformat": "HH:mm:ss", "interpolate": "bezier", "nodata": "", "dot": false, "ymin": "0", "ymax": "50", "removeOlder": 1, "removeOlderPoints": "20", "removeOlderUnit": "3600", "cutout": 0, "useOneColor": false, "useUTC": false, "colors": ["#1f77b4", "#aec7e8", "#ff7f0e", "#2ca02c", "#98df8a", "#d62728", "#ff9896", "#9467bd", "#c5b0d5"], "useOldStyle": false, "outputs": 1, "x": 510, "y": 160, "wires": [["1a8d7b6b.c602a5"]] }, { "id": "d34dca7a.9d33f8", "type": "function", "z": "2e7b0abc.b895c6", "name": "", "func": "msg.payload = Math.round(50*Math.random());\nreturn msg;", "outputs": 1, "noerr": 0, "x": 330, "y": 160, "wires": [["592badab.9a40f4"]] }, { "id": "1a8d7b6b.c602a5", "type": "debug", "z": "2e7b0abc.b895c6", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 730, "y": 160, "wires": [] }, { "id": "99cb9d74.9e3e1", "type": "ui_group", "z": "", "name": "Default", "tab": "ee05c1dc.e4cf9", "order": 1, "disp": true, "width": 11, "collapse": false }, { "id": "ee05c1dc.e4cf9", "type": "ui_tab", "z": "", "name": "Home", "icon": "dashboard", "disabled": false, "hidden": false }];
var app = express();
// Add a simple route for static content served from 'public'
app.use("/", express.static("public"));
// Create a server
var server = http.createServer(app);
// Create the settings object - see default settings.js file for other options
var settings = {
httpAdminRoot: "/red",
httpNodeRoot: "/api",
userDir: "./data/",
functionGlobalContext: {}, // enables global context
disableEditor: false,
// ui: { path: "ui" }
};
// Initialise the runtime with a server and settings
RED.init(server, settings);
// Serve the editor UI
app.use(settings.httpAdminRoot, RED.httpAdmin);
// Serve the http nodes UI
app.use(settings.httpNodeRoot, RED.httpNode);
server.listen(process.env.port || 1880);
RED.start().then(() => {
RED.runtime.flows.setFlows({ flows: { flows } });
});
This is my code. When I try to run this, it does not show me any error on console but my dashboard does not open. Instead a error is thrown in browser console. Same error vanishes if I press "Deploy" from editor UI.
I want to keep editor UI disabled and run it headless.