【问题标题】:How to embed multiple instances of node-red in node app如何在节点应用程序中嵌入多个节点红色实例
【发布时间】:2016-08-29 10:17:17
【问题描述】:

此处的 Node-red 文档提供了有关如何在 nodejs 应用程序中嵌入单个 node-red 应用程序的信息 - http://nodered.org/docs/embedding

我们希望我们网站的用户在不同的端口上拥有自己的 node-red 以进行一些自定义编程。是否可以在 nodejs 应用程序中嵌入多个 node-red 应用程序?

我尝试通过更改具有不同端口的每个调用的设置来重复相同的嵌入步骤,但仅创建一次。第一次,基于设置创建节点红色实例。下次我们调用时,我们会使用端口。我认为这与节点需要做缓存和所有...有关此问题的任何解决方法?

【问题讨论】:

    标签: node.js embed node-red


    【解决方案1】:

    如果您有兴趣,我创建了一个节点红色项目的分支,允许此功能。

    这是你将如何启动它:

    var http = require('http');
    var express = require("express");
    var RED = require("node-red")();
    var RED2 = require("node-red")();
    
    // Create an Express app
    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:"/red1",
        httpNodeRoot: "/api",
        userDir:"./hhh",
        functionGlobalContext: { }    // enables global context
    };
    
    
    
    // Initialise the runtime with a server and settings
    
    RED.init(server,settings);
    
    console.log(RED2.settings === RED.settings, 888, RED2.settings.userSettings);
    
    // Serve the editor UI from /red
    app.use(settings.httpAdminRoot,RED.httpAdmin);
    
    
    // Serve the http nodes UI from /api
    app.use(settings.httpNodeRoot,RED.httpNode);
    
    
    server.listen(8005);
    
    
    // Start the runtime
    RED.start();
    
    
    var app2 = express();
    app2.use("/",express.static("public"));
    var server2 = http.createServer(app2);
    var settings2 = {
        httpAdminRoot:"/red2",
        httpNodeRoot: "/api",
        userDir:"./hhhh",
        functionGlobalContext: { }
    };
    
    RED2.init(server2,settings2);
    app2.use(settings2.httpAdminRoot,RED2.httpAdmin);
    app2.use(settings2.httpNodeRoot,RED2.httpNode);
    
    
    
    RED2.start();
    server2.listen(8006);
    
    console.log(RED.settings.httpAdminRoot);
    console.log(RED2.settings.httpAdminRoot);
    console.log(RED2.settings === RED.settings);
    

    同样,在同一个端口上工作。但确保使用不同的路径是这样的。

    https://github.com/aryeharmon/node-red

    【讨论】:

      【解决方案2】:

      不,目前 Node-RED 没有多用户功能,也无法在一个进程中实例化多个实例。

      您必须为每个用户运行单独的应用程序实例。看看像FRED 这样的例子。这会运行单个实例并代理它们以使集成看起来像是在同一个端口/域上

      【讨论】:

      • 谢谢。我们尝试使用 node-js 中的 exec 并修改设置来创建 node-red 子进程。甚至想到调用一个脚本来启动docker。太麻烦了。所以决定尝试 FRED,即使它的服务在云上。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多