Editor select options from server side data

I have a custom node where I have a property that I want a user to be able to select from a set of dynamically built values. Unfortunately, that list of values itself comes from the result of making a REST call which the browser is not allowed to make but my Node-RED instance (running on the server) can. Reading about the editor I see methods such as oneditprepare() ... but I believe that these will execute in the context of the browser. Is there a recipe where I can populate a property in the editor from the data result of running a function within Node-RED on the server?

To give some background ... I have a node that starts a flow when a message is published to a Google Cloud Platform Pub/Sub topic. When the user configures the node, they must reference an existing subscription by its name. Ideally, I'd like the editor selection to list the known subscription names from which the user can pick/select. The Node-RED engine is executing authority to be able to query the list of subscription names but the browser (which is connected to Node-RED) doesn't have authority to maker the request to the GCP runtime to perform the query directly. It strikes me that since Node-RED (by definition) is already being a Web Server / REST server, I have a "loose feel" that in some theoretical way, the browser showing the editor could make a call to Node-RED to ask Node-RED to return the values that should be shown to the flow designer.

That is how several nodes are designed. You add an endpoint in your JS then call to that from the front-end. The backend does whatever it needs to do then respond with answers/content.
For code examples, I can't remember which of the built-in nodes do this without looking but my cron-plus node does this for building the helper tip.

The example we usually use is the serialport node that has to fetch the list of available ports.


Thank you my friends ... am now going to study the following code fragments ... awesome support!!

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