I have a use case where it would be very convenient for me to be able to specify the URL of a http-in node from an environment variable.
Actually I want to build a generic "webhook" subflow which would be made from
A http_in node
A function node to verify the authentication from the provider
So to make it generic, my subflow would take 2 parameters/environment variables:
the URL => goes into http_in
the key used for authentication => goes into my function node
I would appreciate some pointer to where I could find doc or examples
How to modify the HTML so that the URL can be either a string or an environment variable
How to identify in JS that I directly get the URL or an environment name
I tried to look at Switch and Change but as they are creating things dynamically that a bit next-level for me.
What other node would you suggest me to look into ?
I would be happy to propose a PR is you are interrested
Why not just take the URL directly from the env var in your HTTP_in node? (or am I missing something)
In addition, I would recommend not to use subflows (for various reasons). Ever since the "call link" node has been added to Node-red, it's better to use a reusable group.
Hi @omrid
Are you sure that this syntax is working ?
I will test
Hi @E1cid
Thanks for the suggestion but this is not how I want to proceed
You have a single http_in and then find out which exact route was called and distribute from there
Because of constraint design, I want separated http_in for each route
In addition your suggestion requires the routes to follow the same structure
I would appreciate if you elaborate on that. What are the problem with Subflows ?
Especially in that case, a call-link cannot replace a Subflow with no inputs and only output, especially as the http_in node cannot be configured from a message.
Then what would be the purpose of the subflow, as you can set the url directly in the separate http in nodes.
As to following same structure, not quite true as you can omit :route using a ?, would need more info about your constraint design to explain more.
The subflow does not distribute, you would add a subflow for each different url you wish to use, and configure in the subflow. The subflow would only pass on msg from the http in, if the route matches the subflow config.
Subflows work like macros. behind the scenes they replicate their included nodes. So if you have 10 instances of a subflow of 10 nodes, you would be instantiating 100 nodes. In big projects it will consume a lot of memory and increase the flow load time significantly.
Subflows maintain their own private (per-instance) flow context and environment variables, and this can confuse & complicate things, especially with subflows which are nested within subflows.
The functionality within subflows has some limitations
Having said that, in your case maybe using subflows would be the right approach, since it will allow you to localize the url env variable inside the subflow instance configuration.
Hi @E1cid
Answering to your message about my use-case
The subflow does not distribute, you would add a subflow for each different url you wish to use
This is exactly my purpose
The reasons is we want each flows that process a webhook are independant and can be moved to an another instances easily without relaying on a "distribution flow" (one with 1 single http_in and a big switch)
We prefer letting NodeRed do that for us
Then what would be the purpose of the subflow
The system we are using (SVIX) has 1 different signing key for each webhook
So the idea is to have a subflow with 2 parameters (subflows env variable):
The webhook URL to listen to
The associated signing key
Then in the subflow there would be 2 nodes:
1 http_in that would get it's URL from the env variable
1 function node that does the signature verification
As of today I need to dupplicate this pair of nodes and configure each separately
Having this in the form of a subflow with a single place to configure it would be more convenient.
May be at some point I will code from scratch a SVIX webhook node that does that but I don't have the time for that currently.
Thanks also a lot for your comments about subflows
I have noticed the confusion with their own flow context which cannot be exposed in the GUI. I agree it can makes problems a bit harder to follow.
Regarding memory usage, indeed may be we should check that more deeply. We already use call-link in some occasions for complex "sub flows".
But we really find subflows very nice to avoid coding straight nodes from scratch. Generally our subflows are simple (3-5 nodes) and used only to encapsule http API calls.
The switch would only be 2 rules the env route and otherwise, no other rules would be require, agian the subflow does not distribute, it just checks that it is allowed to receive the incoming requests route, that is cofigured in that instant of the subflow.
The url could be configured in the http in nodes and the key could be added in a change node via any input msg, env, context etc, no subflow required.
[edit]
After testing seems the http in node does not like being in a subflow.
you can do similar using link in out and dynamic link call.
set route in link in nodes and key in change nodes
e.g.