From 380a095bc4ffb89bddc88608b42746084c852b23 Mon Sep 17 00:00:00 2001 From: Ivo Yankulovski Date: Thu, 19 Sep 2019 22:45:35 +0300 Subject: [PATCH] Update base ProtoSSChe server +https support and external config --- README.md | 4 ++++ index.js | 36 +++++++++++++++++++++++++++++------- index.json | 8 +++++--- index.md | 6 +++--- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index f14d224..6d63133 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,7 @@ Folder `modules` contains examples and base extends of the server, including sam Server executes requests non-stop and labels them by unique id **__reqid**, subclass server must extend functionality and create workers using [SkytoSS](https://github.com/ZetaRet/protoss/wiki/SkytoSS-Documentation). [Preview server](https://protoss.zetaret.com/node/) in the browser using PING-shPONGle request returning omitted client data. + +## [Wiki Pages](https://github.com/ZetaRet/protoss-nodejs-basic/wiki) +- [Change log](https://github.com/ZetaRet/protoss-nodejs-basic/wiki/Change-log) +- [HowTo](https://github.com/ZetaRet/protoss-nodejs-basic/wiki/HowTo) \ No newline at end of file diff --git a/index.js b/index.js index a003bb2..af5fc28 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,7 @@ **/ var http = require('http'), + https = require('https'), fs = require('fs'); var env = {}, @@ -244,7 +245,7 @@ class ProtoSSChe { return o; } } -var serverche; +var serverche, sk; if (useXServer) { var xpro = require(xserverModule), xprocls = xpro.getExtendedServerProtoSS(ProtoSSChe); @@ -253,15 +254,36 @@ if (useXServer) { serverche = new ProtoSSChe(); } serverche.env = env; -serverche.htserv = http.createServer(function(req, res) { - try { - serverche.onRequest(req, res); - } catch (e) {} -}); +if (env.statsout && env.statsout.https === true) { + let httpsop = {}; + if (!env.statsout.httpsop) { + httpsop.keyPath = 'key.pem'; + httpsop.certPath = 'cert.pem'; + } else { + for (sk in env.statsout.httpsop) httsop[sk] = env.statsout.httpsop[sk]; + } + if (httpsop.keyPath) httpsop.key = fs.readFileSync(httpsop.keyPath); + if (httpsop.certPath) httpsop.cert = fs.readFileSync(httpsop.certPath); + if (httpsop.pfxPath) httpsop.pfx = fs.readFileSync(httpsop.pfxPath); + if (httpsop.caPath) httpsop.ca = [fs.readFileSync(httpsop.caPath)]; + serverche.htserv = https.createServer(httpsop, function(req, res) { + try { + serverche.onRequest(req, res); + } catch (e) {} + }); +} else { + serverche.htserv = http.createServer(function(req, res) { + try { + serverche.onRequest(req, res); + } catch (e) {} + }); +} +if (!serverche.htserv.request) serverche.htserv.request = http.request; +if (!serverche.htserv.srequest) serverche.htserv.srequest = https.request; if (htport >= 0) serverche.htserv.listen(htport); module.exports.serverclass = ProtoSSChe; module.exports.serverche = serverche; module.exports.setEnv = setEnv; module.exports.resetFSInterval = resetFSInterval; -module.exports.stopFSInterval = stopFSInterval; +module.exports.stopFSInterval = stopFSInterval; \ No newline at end of file diff --git a/index.json b/index.json index ccd9663..a805ac2 100644 --- a/index.json +++ b/index.json @@ -2,8 +2,8 @@ "author": "Zeta Ret", "description": "Basic ProtoSS Node.js Server", "text": "Simple printed server from ProtoSS Packages using XeltoSS synthesis", - "requires": "http, fs", - "version": "1.1.3", + "requires": "http, https, fs", + "version": "1.2.3", "date": "2019 - Today", "supername": "zetaret.node::ProtoSSChe", "inherits": null, @@ -65,7 +65,9 @@ } }, "static_examples": { - "stats": ["{reqnum:3, xserver:true, xserverModule: \"./modules/MyServer.js\", cookieid: \"mycookie\", htport: 3000}"] + "stats": [ + "{reqnum:3, xserver:true, xserverModule: \"./modules/MyServer.js\", cookieid: \"mycookie\", htport: 3000, https: true, httpsop: {keyPath, certPath, pfxPath, caPath, ...anyOtherHTTPSOptionsParameter}" + ] }, "examples": {} } \ No newline at end of file diff --git a/index.md b/index.md index 1bad49d..6593e1e 100644 --- a/index.md +++ b/index.md @@ -1,8 +1,8 @@ > __Author: Zeta Ret__ > __Basic ProtoSS Node.js Server__ # Simple printed server from ProtoSS Packages using XeltoSS synthesis -> *Requires: http, fs* -> *Version: 1.1.3* +> *Requires: http, https, fs* +> *Version: 1.2.3* > *Date: 2019 - Today* __required*__ @@ -140,7 +140,7 @@ default './modules/XProtoSSChe.js', __stats__ Object default init, JSON Object loaded and updated frequently. ``` -{reqnum:3, xserver:true, xserverModule: "./modules/MyServer.js", cookieid: "mycookie", htport: 3000} +{reqnum:3, xserver:true, xserverModule: "./modules/MyServer.js", cookieid: "mycookie", htport: 3000, https: true, httpsop: {keyPath, certPath, pfxPath, caPath, ...anyOtherHTTPSOptionsParameter} ``` ## ### *Static Methods*