diff --git a/google-action.html b/google-action.html
index e41dc54..5e6b659 100644
--- a/google-action.html
+++ b/google-action.html
@@ -39,11 +39,18 @@
-
+
+
+
+
+
-
+
@@ -60,6 +67,8 @@ Properties
port number for server to listen on
url string
url for server to listen on
+ protocol string
+ protocol for the connection
SSL private key file filename
full path to SSL private key file on Node Red server
SSl certificate file filename
@@ -139,8 +148,9 @@ Details
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,
@@ -154,6 +164,20 @@ Details
},
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();
}
});
diff --git a/google-action.js b/google-action.js
index 6cb85e7..0001b23 100644
--- a/google-action.js
+++ b/google-action.js
@@ -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');
@@ -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) => {