mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
fixed comments from @knolleary
This commit is contained in:
17
packages/node_modules/@node-red/util/lib/util.js
vendored
17
packages/node_modules/@node-red/util/lib/util.js
vendored
@@ -419,9 +419,12 @@ function setObjectProperty(msg,prop,value,createMissing) {
|
||||
* @param {String} name - name of variable
|
||||
* @return {String} value of env var
|
||||
*/
|
||||
function getenv(node, name) {
|
||||
if (node && node.getenv) {
|
||||
return node.getenv(name);
|
||||
function getSetting(node, name) {
|
||||
if (node && node._flow) {
|
||||
var flow = node._flow;
|
||||
if (flow) {
|
||||
return flow.getSetting(name);
|
||||
}
|
||||
}
|
||||
return process.env[name];
|
||||
}
|
||||
@@ -442,16 +445,16 @@ function evaluateEnvProperty(value, node) {
|
||||
if (/^\${[^}]+}$/.test(value)) {
|
||||
// ${ENV_VAR}
|
||||
var name = value.substring(2,value.length-1);
|
||||
var val = getenv(node, name);
|
||||
var val = getSetting(node, name);
|
||||
return val ? val : "";
|
||||
} else if (!/\${\S+}/.test(value)) {
|
||||
// ENV_VAR
|
||||
var val = getenv(node, value);
|
||||
var val = getSetting(node, value);
|
||||
return val ? val : "";
|
||||
} else {
|
||||
// FOO${ENV_VAR}BAR
|
||||
return value.replace(/\${([^}]+)}/g, function(match, name) {
|
||||
var val = getenv(node, name);
|
||||
var val = getSetting(node, name);
|
||||
return (val ? val : "");
|
||||
});
|
||||
}
|
||||
@@ -558,7 +561,7 @@ function prepareJSONataExpression(value,node) {
|
||||
return node.context().global.get(val);
|
||||
});
|
||||
expr.assign('env', function(name) {
|
||||
var val = getenv(node, name);
|
||||
var val = getSetting(node, name);
|
||||
return (val ? val : "");
|
||||
})
|
||||
expr.registerFunction('clone', cloneMessage, '<(oa)-:o>');
|
||||
|
Reference in New Issue
Block a user