mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #470 from anna2130/msg-property-overrides
Message properties overriding set node properties
This commit is contained in:
commit
67449eb65a
@ -118,8 +118,7 @@
|
|||||||
|
|
||||||
<script type="text/x-red" data-help-name="http request">
|
<script type="text/x-red" data-help-name="http request">
|
||||||
<p>Provides a node for making http requests.</p>
|
<p>Provides a node for making http requests.</p>
|
||||||
<p>The URL and HTTP method can be configured in the node, but also
|
<p>The URL and HTTP method can be configured in the node, if they are left blank they should be set in an incoming message on <code>msg.url</code> and <code>msg.method</code>:</p>
|
||||||
overridden by the incoming message:
|
|
||||||
<ul>
|
<ul>
|
||||||
<li><code>url</code>, if set, is used as the url of the request. Must start with http: or https:</li>
|
<li><code>url</code>, if set, is used as the url of the request. Must start with http: or https:</li>
|
||||||
<li><code>method</code>, if set, is used as the HTTP method of the request.
|
<li><code>method</code>, if set, is used as the HTTP method of the request.
|
||||||
|
@ -66,9 +66,9 @@ module.exports = function(RED) {
|
|||||||
} else {
|
} else {
|
||||||
node.send({req:req,res:res});
|
node.send({req:req,res:res});
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
var corsHandler = function(req,res,next) { next(); }
|
var corsHandler = function(req,res,next) { next(); };
|
||||||
|
|
||||||
if (RED.settings.httpNodeCors) {
|
if (RED.settings.httpNodeCors) {
|
||||||
corsHandler = cors(RED.settings.httpNodeCors);
|
corsHandler = cors(RED.settings.httpNodeCors);
|
||||||
@ -154,6 +154,9 @@ module.exports = function(RED) {
|
|||||||
node.status({fill:"blue",shape:"dot",text:"requesting"});
|
node.status({fill:"blue",shape:"dot",text:"requesting"});
|
||||||
var url;
|
var url;
|
||||||
if (msg.url) {
|
if (msg.url) {
|
||||||
|
if (n.url) {
|
||||||
|
node.warn("Deprecated: msg properties should not override set node properties. See bit.ly/nr-override-msg-props");
|
||||||
|
}
|
||||||
url = msg.url;
|
url = msg.url;
|
||||||
} else if (isTemplatedUrl) {
|
} else if (isTemplatedUrl) {
|
||||||
url = mustache.render(nodeUrl,msg);
|
url = mustache.render(nodeUrl,msg);
|
||||||
@ -165,7 +168,15 @@ module.exports = function(RED) {
|
|||||||
url = "http://"+url;
|
url = "http://"+url;
|
||||||
}
|
}
|
||||||
|
|
||||||
var method = (msg.method||nodeMethod).toUpperCase();
|
var method;
|
||||||
|
if (msg.method) {
|
||||||
|
if (n.method) {
|
||||||
|
node.warn("Deprecated: msg properties should not override set node properties. See bit.ly/nr-override-msg-props");
|
||||||
|
}
|
||||||
|
method = msg.method.toUpperCase();
|
||||||
|
} else {
|
||||||
|
method = nodeMethod.toUpperCase();
|
||||||
|
}
|
||||||
//node.log(method+" : "+url);
|
//node.log(method+" : "+url);
|
||||||
var opts = urllib.parse(url);
|
var opts = urllib.parse(url);
|
||||||
opts.method = method;
|
opts.method = method;
|
||||||
@ -240,4 +251,4 @@ module.exports = function(RED) {
|
|||||||
password: {type: "password"}
|
password: {type: "password"}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
@ -70,8 +70,8 @@
|
|||||||
|
|
||||||
<script type="text/x-red" data-help-name="e-mail">
|
<script type="text/x-red" data-help-name="e-mail">
|
||||||
<p>Sends the <b>msg.payload</b> as an email, with a subject of <b>msg.topic</b>.</p>
|
<p>Sends the <b>msg.payload</b> as an email, with a subject of <b>msg.topic</b>.</p>
|
||||||
|
<p>The default message recipient can be configured in the node, if it is left blank it should be set in an incoming message on <b>msg.to</b>.</p>
|
||||||
<!-- <p>It sends the message to the configured recipient <i>only</i>.</p> -->
|
<!-- <p>It sends the message to the configured recipient <i>only</i>.</p> -->
|
||||||
<p>You may dynamically overide the default recipient by setting a <b>msg.to</b> property.</p>
|
|
||||||
<!-- <p><b>msg.topic</b> is used to set the subject of the email, and <b>msg.payload</b> is the body text.</p> -->
|
<!-- <p><b>msg.topic</b> is used to set the subject of the email, and <b>msg.payload</b> is the body text.</p> -->
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -72,6 +72,9 @@ module.exports = function(RED) {
|
|||||||
if (smtpTransport) {
|
if (smtpTransport) {
|
||||||
node.status({fill:"blue",shape:"dot",text:"sending"});
|
node.status({fill:"blue",shape:"dot",text:"sending"});
|
||||||
var payload = RED.util.ensureString(msg.payload);
|
var payload = RED.util.ensureString(msg.payload);
|
||||||
|
if (msg.to && node.name) {
|
||||||
|
node.warn("Deprecated: msg properties should not override set node properties. See bit.ly/nr-override-msg-props");
|
||||||
|
}
|
||||||
smtpTransport.sendMail({
|
smtpTransport.sendMail({
|
||||||
from: node.userid, // sender address
|
from: node.userid, // sender address
|
||||||
to: msg.to || node.name, // comma separated list of addressees
|
to: msg.to || node.name, // comma separated list of addressees
|
||||||
@ -243,4 +246,4 @@ module.exports = function(RED) {
|
|||||||
global: { type:"boolean"}
|
global: { type:"boolean"}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
<script type="text/x-red" data-help-name="file">
|
<script type="text/x-red" data-help-name="file">
|
||||||
<p>Writes <b>msg.payload</b> to the file specified, e.g. to create a log.</p>
|
<p>Writes <b>msg.payload</b> to the file specified, e.g. to create a log.</p>
|
||||||
<p>The filename can be overridden by the <b>msg.filename</b> property of the incoming message.</p>
|
<p>The filename can be configured in the node, if left blank it should be set in an incoming message on <b>msg.filename</b>.</p>
|
||||||
<p>A newline is added to every message. But this can be turned off if required, for example, to allow binary files to be written.</p>
|
<p>A newline is added to every message. But this can be turned off if required, for example, to allow binary files to be written.</p>
|
||||||
<p>The default behaviour is to append to the file. This can be changed to overwrite the file each time, for example if you want to output a "static" web page or report.</p>
|
<p>The default behaviour is to append to the file. This can be changed to overwrite the file each time, for example if you want to output a "static" web page or report.</p>
|
||||||
<p>If a <b>msg.delete</b> property exists then the file will be deleted instead.</p>
|
<p>If a <b>msg.delete</b> property exists then the file will be deleted instead.</p>
|
||||||
@ -63,7 +63,7 @@
|
|||||||
|
|
||||||
<script type="text/x-red" data-help-name="file in">
|
<script type="text/x-red" data-help-name="file in">
|
||||||
<p>Reads the specified file and sends the content as <b>msg.payload</b>, and the filename as <b>msg.filename</b>.</p>
|
<p>Reads the specified file and sends the content as <b>msg.payload</b>, and the filename as <b>msg.filename</b>.</p>
|
||||||
<p>The filename can be overridden by the <b>msg.filename</b> property of the incoming message.</p>
|
<p>The filename can be configured in the node, if left blank it should be set in an incoming message on <b>msg.filename</b>.</p>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
@ -25,7 +25,15 @@ module.exports = function(RED) {
|
|||||||
this.overwriteFile = n.overwriteFile;
|
this.overwriteFile = n.overwriteFile;
|
||||||
var node = this;
|
var node = this;
|
||||||
this.on("input",function(msg) {
|
this.on("input",function(msg) {
|
||||||
var filename = msg.filename || this.filename;
|
var filename;
|
||||||
|
if (msg.filename) {
|
||||||
|
if (n.filename) {
|
||||||
|
node.warn("Deprecated: msg properties should not override set node properties. See bit.ly/nr-override-msg-props");
|
||||||
|
}
|
||||||
|
filename = msg.filename;
|
||||||
|
} else {
|
||||||
|
filename = this.filename;
|
||||||
|
}
|
||||||
if (filename === "") {
|
if (filename === "") {
|
||||||
node.warn('No filename specified');
|
node.warn('No filename specified');
|
||||||
} else if (msg.hasOwnProperty('delete')) {
|
} else if (msg.hasOwnProperty('delete')) {
|
||||||
@ -72,7 +80,15 @@ module.exports = function(RED) {
|
|||||||
options['encoding'] = this.format;
|
options['encoding'] = this.format;
|
||||||
}
|
}
|
||||||
this.on("input",function(msg) {
|
this.on("input",function(msg) {
|
||||||
var filename = msg.filename || this.filename;
|
var filename;
|
||||||
|
if (msg.filename) {
|
||||||
|
if (n.filename) {
|
||||||
|
node.warn("Deprecated: msg properties should not override set node properties. See bit.ly/nr-override-msg-props");
|
||||||
|
}
|
||||||
|
filename = msg.filename;
|
||||||
|
} else {
|
||||||
|
filename = this.filename;
|
||||||
|
}
|
||||||
if (filename === "") {
|
if (filename === "") {
|
||||||
node.warn('No filename specified');
|
node.warn('No filename specified');
|
||||||
} else {
|
} else {
|
||||||
@ -92,4 +108,4 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("file in",FileInNode);
|
RED.nodes.registerType("file in",FileInNode);
|
||||||
}
|
};
|
||||||
|
@ -200,7 +200,7 @@
|
|||||||
<p>Find queries a collection using the <b>msg.payload</b> as the query statement as per the .find() function. Optionally, you may also (via a function) set a <b>msg.projection</b> object to constrain the returned fields, a <b>msg.sort</b> object and a <b>msg.limit</b> object.</p>
|
<p>Find queries a collection using the <b>msg.payload</b> as the query statement as per the .find() function. Optionally, you may also (via a function) set a <b>msg.projection</b> object to constrain the returned fields, a <b>msg.sort</b> object and a <b>msg.limit</b> object.</p>
|
||||||
<p>Count returns a count of the number of documents in a collection or matching a query using the <b>msg.payload</b> as the query statement.</p>
|
<p>Count returns a count of the number of documents in a collection or matching a query using the <b>msg.payload</b> as the query statement.</p>
|
||||||
<p>Aggregate provides access to the aggregation pipeline using the <b>msg.payload</b> as the pipeline array.</p>
|
<p>Aggregate provides access to the aggregation pipeline using the <b>msg.payload</b> as the pipeline array.</p>
|
||||||
<p>You can override the collection the method is performed on by setting <b>msg.collection</b> to the desired collection name.</p>
|
<p>You can either set the collection method in the node config or on <b>msg.collection</b>. Setting it in the node will override <b>msg.collection</b>.</p>
|
||||||
<p>See the <a href="http://docs.mongodb.org/manual/reference/method/db.collection.find/" target="new"><i>MongoDB collection methods docs</i></a> for examples.</p>
|
<p>See the <a href="http://docs.mongodb.org/manual/reference/method/db.collection.find/" target="new"><i>MongoDB collection methods docs</i></a> for examples.</p>
|
||||||
<p>The result is returned in <b>msg.payload</b>.</p>
|
<p>The result is returned in <b>msg.payload</b>.</p>
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user