Controlling the rules from external front end (React JS)

Hello community,

I have a flow on my node red with certain rules set on the message object values (the value of objects are either sensor values or status of a sensor). And let's say I want to control the rules from the front end (created using React JS) without actually having access to the node-RED flow.

Is it possible to migrate the script of the flow? Or expose the endpoints of particular nodes so that you can change certain rules from front end? (Some of the rules are written in script form in the function node and others in the Switch node)

If not possible with Node-RED what approach would you suggest for this problem? Another rule engine you might know that allows this?

Any input would be greatly appreciated.
Thank you.

You can easily add endpoints in your flow that can set/reset flags that redirect the flow of messages.

See the cookbook for examples. Node-RED Cookbook : Node-RED

1 Like

Hi @Steve-Mcl,

Thank you for your reply.

Adding endpoints might be the way to go. Could you please elaborate a bit on how it would change a specific value stored in a msg.property for example? Does the http endpoint node create an endpoint of a msg.property? Something like this
"http://localhost:1880/msg.property"
? This is obviously just an example.

And assuming these values are changed from the front end, will I have to restart node red to implement?

Have a look at the http examples in the node red cookbook

1 Like

@Steve-Mcl
@Colin
The endpoints I created are local to my server. But if I want to change rules or send data to this endpoint from a different server/cloud service, I need to publicly expose the endpoint.

How can I do that?

One option to do this could be mqtt/apis but I was wondering if we could generate endpoints which could be publicly exposed. My purpose is to get data and also to change certain rules in the switch node using an endpoint.

That is certainly possible, but there are security risks in doing that, so do not do that if you do not understand all the implications. There have been many posts here on how to secure node-red for public access.
A possible solution that does not involve opening up the endpoint is to use a cloud MQTT broker and connect to that from node red and your external system.

Thanks for your reply @Colin
I'll be sure to check it out.
I did consider the mqtt option but I'm not sure if that would solve both problems. I need to be able to change the rules set in the switch node from the front end. And that shouldn't be using a local endpoint but publicly exposed. I will look into the security issues concerning publicly exposed node red but is there another way to do this?

Why doesn't mqtt solve the problem? The front end can publish the requirement to MQTT and node-red can subscribe to that topic in order to know what to do.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.