From da535b3e8735a062f9d503c496b6397389406689 Mon Sep 17 00:00:00 2001 From: Vivek Khurana Date: Fri, 17 Aug 2018 12:50:25 -0700 Subject: [PATCH 1/2] add http support --- google-action.html | 32 ++++++++++++++++++++++++++++---- google-action.js | 21 ++++++++++++++------- 2 files changed, 42 insertions(+), 11 deletions(-) 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..ae6f3ef 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'); @@ -50,15 +51,21 @@ module.exports = function(RED) { node.key = n.key || ''; node.cert = n.cert || ''; - 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) => { From ec590e1ba09b62ed73f3adc869ab6e3544de869e Mon Sep 17 00:00:00 2001 From: Vivek Khurana Date: Fri, 17 Aug 2018 12:59:06 -0700 Subject: [PATCH 2/2] default to https --- google-action.js | 1 + 1 file changed, 1 insertion(+) diff --git a/google-action.js b/google-action.js index ae6f3ef..0001b23 100644 --- a/google-action.js +++ b/google-action.js @@ -50,6 +50,7 @@ module.exports = function(RED) { node.port = n.port || 8081; node.key = n.key || ''; node.cert = n.cert || ''; + node.protocol = n.protocol || 'https'; // Create new http server to listen for requests var expressApp = express();