Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions google-action.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,18 @@
<input id="node-input-url" type="text" placeholder="/">
</div>
<div class="form-row">
<label for="node-input-key"><i class="fa fa-tag"></i> SSL Private Key File</span></label>
<label for="node-input-protocol"><i class="fa fa-tag"></i> Protocol</span></label>
<select id="node-input-protocol">
<option value="http">HTTP</option>
<option value="https">HTTPS</option>
</select>
</div>
<div class="form-row">
<label id="node-input-label-key" for="node-input-key"><i class="fa fa-tag"></i> SSL Private Key File</span></label>
<input id="node-input-key" type="text" placeholder="/path/on/server/to/private.key">
</div>
<div class="form-row">
<label for="node-input-cert"><i class="fa fa-tag"></i> SSL Certificate File</span></label>
<label id="node-input-label-cert" for="node-input-cert"><i class="fa fa-tag"></i> SSL Certificate File</span></label>
<input id="node-input-cert" type="text" placeholder="/path/on/server/to/certificate.crt">
</div>
</script>
Expand All @@ -60,6 +67,8 @@ <h3>Properties</h3>
<dd>port number for server to listen on </dd>
<dt>url <span class="property-type"> string</span><dt>
<dd>url for server to listen on </dd>
<dt>protocol <span class="property-type"> string</span><dt>
<dd>protocol for the connection </dd>
<dt>SSL private key file <span class="property-type">filename </span><dt>
<dd>full path to SSL private key file on Node Red server</dd>
<dt>SSl certificate file <span class="property-type">filename </span><dt>
Expand Down Expand Up @@ -139,8 +148,9 @@ <h3>Details</h3>
topic: {value:""},
port: {value:"8081",required:true, validate: RED.validators.number()},
url: {value:"/", required:true},
key: {value:"", requred:true},
cert: {value: "", required:true}
protocol: {value:"https", required:true},
key: {value:"" },
cert: {value:"" }
},
inputs:0,
outputs:1,
Expand All @@ -154,6 +164,20 @@ <h3>Details</h3>
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {

$("#node-input-protocol").change(function() {
var protocol = $("#node-input-protocol option:selected").val();
if (protocol == "https") {
$("#node-input-key, #node-input-cert, #node-input-label-cert, #node-input-label-key").show();
} else {
$("#node-input-key, #node-input-cert, #node-input-label-cert, #node-input-label-key").hide();
}
});

$("#node-input-protocol").val(this.protocol);
$("#node-input-protocol").change();
}
});

Expand Down
22 changes: 15 additions & 7 deletions google-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = function(RED) {

const express = require('express');
const https = require("https");
const http = require("http");
const fs = require('fs');

const bodyParser = require('body-parser');
Expand All @@ -49,16 +50,23 @@ module.exports = function(RED) {
node.port = n.port || 8081;
node.key = n.key || '';
node.cert = n.cert || '';
node.protocol = n.protocol || 'https';

const options = {
key: fs.readFileSync(node.key),
cert: fs.readFileSync(node.cert)
};

// Create new http server to listen for requests
// Create new http server to listen for requests
var expressApp = express();
expressApp.use(bodyParser.json({ type: 'application/json' }));
node.httpServer = https.createServer(options, expressApp);

if (node.protocol === "https") {
const options = {
key: fs.readFileSync(node.key),
cert: fs.readFileSync(node.cert)
};

node.httpServer = https.createServer(options, expressApp);
} else {
node.httpServer = http.createServer(expressApp);
}


// Handler for requests
expressApp.all(node.url, (request, response) => {
Expand Down