红色节点:RED.httpAdmin.get-动态配置

我正在创建一个将信息保存到Mongo BD的自定义节点。根据mongo DB中的记录,我在节点模块中有一个下拉列表。我在配置节点中使用RED.httpAdmin.get构建下拉列表。但是,当前与RED.httpAdmin.get中的Mongo数据库的连接是硬编码的。有没有一种方法可以遍历所有已保存的配置并为每个配置构建单独的端点。

这是当前代码:

RED.httpAdmin.get("/vswitch",RED.auth.needsPermission('vswitch.read'),function(req,res) {

    var ma = require('./mongoactions.js');

    //this is where I would like to make it dynamic for each configuration
    var url = "mongodb://127.0.0.1:27017/archie"
    var database = "archie"
    var collection = "switches"
    var search = ""

    ma.findAll(url,search,database,collection).then(function(result) {
        allSwitches = [{value:"All",label:"*",hasValue:false}]
        result.sort((a,b) => (a.payload.vswitch > b.payload.vswitch) ? 1 : -1)

        result.forEach(vswitch=> {
            try {
                vname = vswitch.payload.vswitch
                vlabel = vswitch.payload.vswitch
                jsonSwitch = {value:vname,label:vlabel,hasValue:false}
                allSwitches.push(jsonSwitch)
            } catch(err) {
                console.log("switch not found")
            }
        });

        res.json(allSwitches);
        },function(err) {
            result = err;
        })
});

感谢您的帮助。

pldljf 回答:红色节点:RED.httpAdmin.get-动态配置

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3089208.html

大家都在问