mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add env-var support to TypedInput
This commit is contained in:
@@ -303,6 +303,23 @@ function setMessageProperty(msg,prop,value,createMissing) {
|
||||
}
|
||||
}
|
||||
|
||||
function evaluteEnvProperty(value) {
|
||||
if (/^\${[^}]+}$/.test(value)) {
|
||||
// ${ENV_VAR}
|
||||
value = value.substring(2,value.length-1);
|
||||
value = process.env.hasOwnProperty(value)?process.env[value]:""
|
||||
} else if (!/\${\S+}/.test(value)) {
|
||||
// ENV_VAR
|
||||
value = process.env.hasOwnProperty(value)?process.env[value]:""
|
||||
} else {
|
||||
// FOO${ENV_VAR}BAR
|
||||
value = value.replace(/\${([^}]+)}/g, function(match, v) {
|
||||
return process.env.hasOwnProperty(v)?process.env[v]:""
|
||||
});
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function evaluateNodeProperty(value, type, node, msg) {
|
||||
if (type === 'str') {
|
||||
return ""+value;
|
||||
@@ -328,6 +345,8 @@ function evaluateNodeProperty(value, type, node, msg) {
|
||||
} else if (type === 'jsonata') {
|
||||
var expr = prepareJSONataExpression(value,node);
|
||||
return evaluateJSONataExpression(expr,msg);
|
||||
} else if (type === 'env') {
|
||||
return evaluteEnvProperty(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
Reference in New Issue
Block a user