mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge pull request #3690 from cow0w/env_evalulating_in_template
Add support for evalulating {{env.<var>}} within a template node
This commit is contained in:
@@ -44,6 +44,14 @@ module.exports = function(RED) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function parseEnv(key) {
|
||||
var match = /^env\.(.+)/.exec(key);
|
||||
if (match) {
|
||||
return match[1];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom Mustache Context capable to collect message property and node
|
||||
* flow and global context
|
||||
@@ -74,6 +82,11 @@ module.exports = function(RED) {
|
||||
return value;
|
||||
}
|
||||
|
||||
// try env
|
||||
if (parseEnv(name)) {
|
||||
return this.cachedContextTokens[name];
|
||||
}
|
||||
|
||||
// try flow/global context:
|
||||
var context = parseContext(name);
|
||||
if (context) {
|
||||
@@ -156,6 +169,17 @@ module.exports = function(RED) {
|
||||
var tokens = extractTokens(mustache.parse(template));
|
||||
var resolvedTokens = {};
|
||||
tokens.forEach(function(name) {
|
||||
var env_name = parseEnv(name);
|
||||
if (env_name) {
|
||||
var promise = new Promise((resolve, reject) => {
|
||||
var val = RED.util.evaluateNodeProperty(env_name, 'env', node)
|
||||
resolvedTokens[name] = val;
|
||||
resolve();
|
||||
});
|
||||
promises.push(promise);
|
||||
return;
|
||||
}
|
||||
|
||||
var context = parseContext(name);
|
||||
if (context) {
|
||||
var type = context.type;
|
||||
|
Reference in New Issue
Block a user