mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
0b1c14c07e
@ -76,7 +76,7 @@
|
||||
outputs:1,
|
||||
icon: "white-globe.png",
|
||||
label: function() {
|
||||
return this.name||"["+this.method+"] "+this.url;
|
||||
return this.name||(this.url?("["+this.method+"] "+this.url):"http");
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name?"node_label_italic":"";
|
||||
@ -85,14 +85,19 @@
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-template-name="http response">
|
||||
<div class="form-tips">The messages sent to this node must originate from an HTTP input node</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-tips">The messages sent to this node <b>must</b> originate from an <i>http input</i> node</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="http response">
|
||||
<p>Provides an response node for http requests received from an http input node.</p>
|
||||
<p>Sends responses back to http requests received from an HTTP Input node.</p>
|
||||
<p>The response can be customised using the following message properties:</p>
|
||||
<ul>
|
||||
<li><code>payload</code> is sent as the body of the reponse</li>
|
||||
<li><code>rc</code>, if set, is used as the response code (default: 200)</li>
|
||||
<li><code>statusCode</code>, if set, is used as the response status code (default: 200)</li>
|
||||
<li><code>headers</code>, if set, should be an object containing field/value
|
||||
pairs to be added as response headers.</li>
|
||||
</ul>
|
||||
@ -102,17 +107,89 @@
|
||||
RED.nodes.registerType('http response',{
|
||||
category: 'output',
|
||||
color:"rgb(231, 231, 174)",
|
||||
defaults: {},
|
||||
defaults: {
|
||||
name: {value:""}
|
||||
},
|
||||
inputs:1,
|
||||
outputs:0,
|
||||
align: "right",
|
||||
icon: "white-globe.png",
|
||||
label: function() {
|
||||
return "http"
|
||||
return this.name||"http";
|
||||
},
|
||||
labelStyle: function() {
|
||||
return "";
|
||||
return this.name?"node_label_italic":"";
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
<script type="text/x-red" data-template-name="http request">
|
||||
<div class="form-row">
|
||||
<label for="node-input-method"><i class="icon-tasks"></i> Method</label>
|
||||
<select type="text" id="node-input-method" style="width: 150px;">
|
||||
<option value="GET">GET</option>
|
||||
<option value="POST">POST</option>
|
||||
<option value="PUT">PUT</option>
|
||||
<option value="DELETE">DELETE</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-url"><i class="icon-tasks"></i> URL</label>
|
||||
<input type="text" id="node-input-url" placeholder="http://">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="http request">
|
||||
<p>Provides a node for making http requests.</p>
|
||||
<p>The URL and HTTP method can be configured in the node, but also
|
||||
overridden by the incoming message:
|
||||
<ul>
|
||||
<li><code>url</code>, if set, is used as the url of the request</li>
|
||||
<li><code>method</code>, if set, is used as the HTTP method of the request. Must be one of <code>GET</code>, <code>PUT</code>, <code>POST</code> or <code>DELETE</code> (default: GET)</li>
|
||||
<li><code>headers</code>, if set, should be an object containing field/value
|
||||
pairs to be added as request headers</li>
|
||||
<li><code>payload</code> is sent as the body of the request</li>
|
||||
</ul>
|
||||
|
||||
The output message contains the following properties:
|
||||
<ul>
|
||||
<li><code>payload</code> is the body of the response</li>
|
||||
<li><code>statusCode</code> is the status code of the response, or the error code if the request could not be completed</li>
|
||||
<li><code>headers</code> is an object containing the response headers</li>
|
||||
</ul>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('http request',{
|
||||
category: 'function',
|
||||
color:"rgb(231, 231, 174)",
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
method:{value:"GET"},
|
||||
url:{value:""}
|
||||
},
|
||||
inputs:1,
|
||||
outputs:1,
|
||||
align: "right",
|
||||
icon: "white-globe.png",
|
||||
label: function() {
|
||||
return this.name||"http request";
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name?"node_label_italic":"";
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -16,6 +16,10 @@
|
||||
|
||||
var RED = require("../../red/red");
|
||||
var util = require("util");
|
||||
var http = require("http");
|
||||
var https = require("https");
|
||||
var urllib = require("url");
|
||||
var bodyParser = require("express").bodyParser();
|
||||
|
||||
function HTTPIn(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
@ -24,14 +28,15 @@ function HTTPIn(n) {
|
||||
|
||||
var node = this;
|
||||
this.callback = function(req,res) {
|
||||
console.log(arguments.length);
|
||||
node.send({req:req,res:res});
|
||||
}
|
||||
if (this.method == "get") {
|
||||
RED.app.get(this.url,this.callback);
|
||||
} else if (this.method == "post") {
|
||||
RED.app.post(this.url,this.callback);
|
||||
RED.app.post(this.url,bodyParser,this.callback);
|
||||
} else if (this.method == "put") {
|
||||
RED.app.put(this.url,this.callback);
|
||||
RED.app.put(this.url,bodyParser,this.callback);
|
||||
} else if (this.method == "delete") {
|
||||
RED.app.delete(this.url,this.callback);
|
||||
}
|
||||
@ -41,7 +46,7 @@ function HTTPIn(n) {
|
||||
for (var i in routes) {
|
||||
if (routes[i].path == this.url) {
|
||||
routes.splice(i,1);
|
||||
break;
|
||||
//break;
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -58,10 +63,59 @@ function HTTPOut(n) {
|
||||
if (msg.headers) {
|
||||
res.set(msg.headers);
|
||||
}
|
||||
var rc = msg.rc || 200;
|
||||
msg.res.send(rc,msg.payload);
|
||||
var statusCode = msg.statusCode || 200;
|
||||
msg.res.send(statusCode,msg.payload);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
RED.nodes.registerType("http response",HTTPOut);
|
||||
|
||||
function HTTPRequest(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
var url = n.url;
|
||||
var method = n.method || "GET";
|
||||
var httplib = (/^https/.test(url))?https:http;
|
||||
var node = this;
|
||||
this.on("input",function(msg) {
|
||||
|
||||
var opts = urllib.parse(msg.url||url);
|
||||
opts.method = msg.method||method;
|
||||
if (msg.headers) {
|
||||
opts.header = headers;
|
||||
}
|
||||
var req = httplib.request(opts,function(res) {
|
||||
res.setEncoding('utf8');
|
||||
var message = {
|
||||
statusCode: res.statusCode,
|
||||
headers: res.headers,
|
||||
payload: ""
|
||||
};
|
||||
res.on('data',function(chunk) {
|
||||
message.payload += chunk;
|
||||
});
|
||||
res.on('end',function() {
|
||||
node.send(message);
|
||||
});
|
||||
});
|
||||
req.on('error',function(err) {
|
||||
msg.payload = err.toString();
|
||||
msg.statusCode = err.code;
|
||||
node.send(msg);
|
||||
});
|
||||
if (msg.payload) {
|
||||
if (typeof msg.payload === "string" || Buffer.isBuffer(msg.payload)) {
|
||||
req.write(msg.payload);
|
||||
} else if (typeof msg.payload == "number") {
|
||||
req.write(msg.payload+"");
|
||||
} else {
|
||||
req.write(JSON.stringify(msg.payload));
|
||||
}
|
||||
}
|
||||
req.end();
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
RED.nodes.registerType("http request",HTTPRequest);
|
||||
|
@ -15,6 +15,8 @@
|
||||
-->
|
||||
|
||||
<script type="text/x-red" data-template-name="httpget">
|
||||
<div class="form-tips"><b>Deprecated</b>: please use the <i>http request</i> node.</div>
|
||||
<br>
|
||||
<div class="form-row">
|
||||
<label for="node-input-baseurl"><i class="icon-tasks"></i> Base URL</label>
|
||||
<input type="text" id="node-input-baseurl" placeholder="http(s)://url">
|
||||
|
@ -32,8 +32,10 @@
|
||||
<script type="text/x-red" data-help-name="prowl">
|
||||
<p>Uses Prowl to push the <b>msg.payload</b> to an Apple device that has the prowl app installed.</p>
|
||||
<p>Optionally uses <b>msg.topic</b> to set the title. You can also set <b>msg.priority</b> to confgure the urgency from -2 (low), through 0 (normal) to 2 (urgent).</p>
|
||||
<p>You MUST configure your prowl API key into the pushkey.js file in the directory above node-red.</p>
|
||||
<p><pre>module.exports = { prowl:'My-API-KEY' }</pre></p>
|
||||
<p>You MUST configure your prowl API key into either the settings.js file like this</p>
|
||||
<p><pre>prowl: { prowlkey:'My-API-KEY' },</pre></p>
|
||||
<p>Or into a pushkey.js file in the directory <b>above</b> node-red.</p>
|
||||
<p><pre>module.exports = { prowlkey:'My-API-KEY' }</pre></p>
|
||||
<p>Uses Prowl so see <i><a href="https://www.prowlapp.com" target="_new">this link</a></i> for more details.</p>
|
||||
</script>
|
||||
|
||||
|
@ -16,17 +16,23 @@
|
||||
|
||||
var RED = require("../../red/red");
|
||||
var Prowl = require('node-prowl');
|
||||
var util = require('util');
|
||||
|
||||
// pushkey.js just needs to be like (with the quotes)
|
||||
// module.exports = {prowl:'My-API-KEY'}
|
||||
// Either add a line like this to settings.js
|
||||
// prowl: {prowlkey:'My-API-KEY'},
|
||||
// or create pushkey.js in dir ABOVE node-red, it just needs to be like
|
||||
// module.exports = {prowlkey:'My-API-KEY'}
|
||||
|
||||
try {
|
||||
var pushkey = require("../../settings").prowl || require("../../../pushkey.js");
|
||||
} catch(err) {
|
||||
throw new Error("Failed to load Prowl credentials");
|
||||
}
|
||||
catch(err) {
|
||||
util.log("[57-prowl.js] Error: Failed to load Prowl credentials");
|
||||
}
|
||||
|
||||
var prowl = new Prowl(pushkey.prowl);
|
||||
if (pushkey) {
|
||||
var prowl = new Prowl(pushkey.prowlkey);
|
||||
}
|
||||
|
||||
function ProwlNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
@ -41,14 +47,19 @@ function ProwlNode(n) {
|
||||
if (typeof(msg.payload) == 'object') {
|
||||
msg.payload = JSON.stringify(msg.payload);
|
||||
}
|
||||
try {
|
||||
prowl.push(msg.payload, titl, { priority: pri }, function( err, remaining ){
|
||||
if ( err ) node.error(err);
|
||||
node.log( remaining + ' calls to Prowl api during current hour.' );
|
||||
});
|
||||
if (pushkey) {
|
||||
try {
|
||||
prowl.push(msg.payload, titl, { priority: pri }, function(err, remaining) {
|
||||
if (err) node.error(err);
|
||||
node.log( remaining + ' calls to Prowl api during current hour.' );
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
node.error(err);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
node.error(err);
|
||||
else {
|
||||
node.warn("Prowl credentials not set/found. See node info.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -16,13 +16,9 @@
|
||||
|
||||
<script type="text/x-red" data-template-name="pushbullet">
|
||||
<div class="form-row">
|
||||
<label for="node-input-title"><i class="icon-tag"></i> Title</label>
|
||||
<label for="node-input-title"><i class="icon-flag"></i> Title</label>
|
||||
<input type="text" id="node-input-title" placeholder="Node-RED">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-priority"><i class="icon-tag"></i> Priority</label>
|
||||
<input type="text" id="node-input-priority" placeholder="0">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
@ -31,9 +27,11 @@
|
||||
|
||||
<script type="text/x-red" data-help-name="pushbullet">
|
||||
<p>Uses PushBullet to push the <b>msg.payload</b> to an Android device that has PushBullet app installed.</p>
|
||||
<p>Optionally uses <b>msg.topic</b> to set the title.</p>
|
||||
<p>You MUST configure both your API key and the target device ID into the pushkey.js file in the directory above node-red.<p>
|
||||
<p><pre>>module.exports = { pushbullet:'My-API-KEY', deviceid:'12345' }</pre</p>
|
||||
<p>Optionally uses <b>msg.topic</b> to set the title, if not already set in the properties.</p>
|
||||
<p>You MUST configure both your API key and the target device ID. Either into settings.js like this</p>
|
||||
<p><pre>pushbullet: { pushbullet:'My-API-KEY', deviceid:'12345' },</pre></p>
|
||||
<p>Or as a pushkey.js file in the directory <b>above</b> node-red.<p>
|
||||
<p><pre>module.exports = { pushbullet:'My-API-KEY', deviceid:'12345' }</pre></p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
@ -41,7 +39,6 @@
|
||||
category: 'output',
|
||||
defaults: {
|
||||
title: {value:""},
|
||||
priority: {value:0,required:true,validate:RED.validators.number()},
|
||||
name: {value:""}
|
||||
},
|
||||
color:"#a7c9a0",
|
||||
|
@ -16,37 +16,47 @@
|
||||
|
||||
var RED = require("../../red/red");
|
||||
var PushBullet = require('pushbullet');
|
||||
var util = require('util');
|
||||
|
||||
// pushkey.js just needs to be like (with the quotes)
|
||||
// module.exports = {pushbullet:'My-API-KEY', deviceid:'12345'}
|
||||
// Either add a line like this to settings.js
|
||||
// pushbullet: {pushbullet:'My-API-KEY', deviceid:'12345'},
|
||||
// or create pushkey.js in dir ABOVE node-red, it just needs to be like
|
||||
// module.exports = {pushbullet:'My-API-KEY', deviceid:'12345'}
|
||||
|
||||
try {
|
||||
var pushkey = require("../../settings").pushbullet || require("../../../pushkey.js");
|
||||
} catch(err) {
|
||||
throw new Error("Failed to load PushBullet credentials");
|
||||
}
|
||||
catch(err) {
|
||||
util.log("[57-pushbullet.js] Error: Failed to load PushBullet credentials");
|
||||
}
|
||||
|
||||
var pusher = new PushBullet(pushkey.pushbullet);
|
||||
var deviceId = pushkey.deviceid;
|
||||
if (pushkey) {
|
||||
var pusher = new PushBullet(pushkey.pushbullet);
|
||||
var deviceId = pushkey.deviceid;
|
||||
}
|
||||
|
||||
function PushbulletNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.title = n.title;
|
||||
this.device
|
||||
var node = this;
|
||||
this.on("input",function(msg) {
|
||||
var titl = this.title||msg.topic||"Node-RED";
|
||||
if (typeof(msg.payload) == 'object') {
|
||||
msg.payload = JSON.stringify(msg.payload);
|
||||
}
|
||||
try {
|
||||
pusher.note(deviceId, titl, msg.payload, function(err, response) {
|
||||
if ( err ) node.error(err);
|
||||
node.log( JSON.stringify(response) );
|
||||
});
|
||||
if (pushkey) {
|
||||
try {
|
||||
pusher.note(deviceId, titl, msg.payload, function(err, response) {
|
||||
if (err) node.error(err);
|
||||
console.log(response);
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
node.error(err);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
node.error(err);
|
||||
else {
|
||||
node.warn("Pushbullet credentials not set/found. See node info.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user