Ver Fonte

reflector as npm module too and update license info

Nikolay Suslov há 6 anos atrás
pai
commit
bd8c33ace0
13 ficheiros alterados com 403 adições e 304 exclusões
  1. 7 2
      .gitignore
  2. 3 15
      LICENSE.md
  3. 9 2
      README.md
  4. 13 0
      VWF_LICENSE.md
  5. 8 0
      config_example.json
  6. 10 0
      index.js
  7. 4 1
      lib/reflector.js
  8. 0 6
      node-server.js
  9. 26 45
      node_vwf.js
  10. 205 222
      package-lock.json
  11. 8 11
      package.json
  12. 28 0
      server/logger.js
  13. 82 0
      server/readConfig.js

+ 7 - 2
.gitignore

@@ -1,5 +1,10 @@
 # Node.js
 # Node.js
+.vscode
+
 node_modules
 node_modules
-/npm-debug.log
 certs
 certs
-.vscode
+
+npm-debug.log
+config.json
+error.log
+combined.log

+ 3 - 15
LICENSE.md

@@ -1,4 +1,4 @@
-LiveCoding.space
+Krestianstvo.org
 The MIT License (MIT)
 The MIT License (MIT)
 Copyright (c) 2018 Nikolai Suslov
 Copyright (c) 2018 Nikolai Suslov
 
 
@@ -20,17 +20,5 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 SOFTWARE.
 
 
-
-Virtual World Framework
-Copyright 2012 United States Government, as represented by the Secretary of Defense, Under
-Secretary of Defense (Personnel & Readiness).
-
-Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
-in compliance with the License. You may obtain a copy of the License at
-
-http:www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software distributed under the License
-is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
-or implied. See the License for the specific language governing permissions and limitations under
-the License.
+-----
+A different license may apply to other software included in this package. Please consult their respective license files for the terms of their individual licenses.

+ 9 - 2
README.md

@@ -1,5 +1,12 @@
 # LiveCoding.space reflector
 # LiveCoding.space reflector
 
 
-Standalone message reflector for LiveCoding.space application (base on VWF reflector)
-time.livecoding.space
+Standalone message reflector for LiveCoding.space application (base on VWF reflector)  
+Live at [https://time.livecoding.space](https://time.livecoding.space)
 
 
+
+## Contributing
+
+All code is published under the [MIT license](https://github.com/NikolaySuslov/lcs-reflector/blob/master/LICENSE.md)
+
+A different license may apply to other software included in this package. Please consult their respective license files for the terms of their individual licenses:     
+[VWF Apache License](https://github.com/NikolaySuslov/lcs-reflector/blob/master/VWF_LICENSE.md)

+ 13 - 0
VWF_LICENSE.md

@@ -0,0 +1,13 @@
+Virtual World Framework
+Copyright 2012 United States Government, as represented by the Secretary of Defense, Under
+Secretary of Defense (Personnel & Readiness).
+
+Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+in compliance with the License. You may obtain a copy of the License at
+
+http:www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software distributed under the License
+is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+or implied. See the License for the specific language governing permissions and limitations under
+the License.

+ 8 - 0
config_example.json

@@ -0,0 +1,8 @@
+{
+    "ssl": true,
+    "port": 3001,
+    "sslKey":"./certs/server-key.pem",
+    "sslCert":"./certs/server-crt.pem",
+    "sslCA":"./certs/ca-crt.pem",
+    "certPwd": ""
+}

+ 10 - 0
index.js

@@ -0,0 +1,10 @@
+// Copyright (c) 2018 Nikolai Suslov
+// Krestianstvo.org MIT license (https://github.com/NikolaySuslov/lcs-reflector/blob/master/LICENSE.md)
+
+var reflector = require('./lib/reflector')
+module.exports = reflector
+
+if (!module.parent) {
+    var server = require('./node_vwf');
+    server.startVWF(reflector);
+}

+ 4 - 1
lib/reflector.js

@@ -1,5 +1,8 @@
+// Copyright (c) 2018 Nikolai Suslov
+// Krestianstvo.org MIT license (https://github.com/NikolaySuslov/lcs-reflector/blob/master/LICENSE.md)
+// VWF Apache License (https://github.com/NikolaySuslov/lcs-reflector/blob/master/VWF_LICENSE.md)
+
 "use strict";
 "use strict";
-// reflector.js
 
 
 // JoinPath
 // JoinPath
 // Takes multiple arguments, joins them together into one path.
 // Takes multiple arguments, joins them together into one path.

+ 0 - 6
node-server.js

@@ -1,6 +0,0 @@
-#!/usr/bin/env node
-
-var server = require( './node_vwf' );
-
-server.startVWF();
-

+ 26 - 45
node_vwf.js

@@ -1,20 +1,12 @@
+// Copyright (c) 2018 Nikolai Suslov
+// Krestianstvo.org MIT license (https://github.com/NikolaySuslov/lcs-reflector/blob/master/LICENSE.md)
+// VWF Apache License (https://github.com/NikolaySuslov/lcs-reflector/blob/master/VWF_LICENSE.md)
+
 var http = require('http'),
 var http = require('http'),
     https = require('https'),
     https = require('https'),
-    fs = require('fs'),
+    argv = require('optimist').argv,
     sio = require('socket.io'),
     sio = require('socket.io'),
-    reflector = require('./lib/reflector'),
-    argv = require('optimist').argv;
-
-
-function printGeneralHelp() {
-    console.log("Options:");
-    console.log("  -p, --port               Port to start server on. Default: 3000");
-    console.log("  -l, --log                Log level for server. Default: 1");
-    console.log("  -h, --help               Output usage information");
-    console.log("  -s, --ssl                Enables SSL");
-    console.log("  -k, --key                Path to private key");
-    console.log("  -c, --cert               Path to certificate");
-}
+    config = require('./server/readConfig')
 
 
 
 
 // Basic logging function.
 // Basic logging function.
@@ -46,24 +38,28 @@ function consoleError(string) {
     global.log(red + string + reset);
     global.log(red + string + reset);
 }
 }
 
 
+
+
 //Start the VWF server
 //Start the VWF server
-function startVWF() {
+function startVWF(reflector) {
+
+    config.readConfigFile();
 
 
     global.logLevel = ((argv.l || argv.log) ? (argv.l || argv.log) : 1);
     global.logLevel = ((argv.l || argv.log) ? (argv.l || argv.log) : 1);
     global.instances = {};
     global.instances = {};
 
 
-    function serve(request, response){
+    function serve(request, response) {
 
 
-        response.writeHead( 200, {
+        response.writeHead(200, {
             "Content-Type": "application/json"
             "Content-Type": "application/json"
-        } );
+        });
         var inst = Object.keys(global.instances);
         var inst = Object.keys(global.instances);
         var jsonobject = {
         var jsonobject = {
             "reflector": "v0.0.2"
             "reflector": "v0.0.2"
             //"instances": inst
             //"instances": inst
         }
         }
-        response.write( JSON.stringify( jsonobject ), "utf8" );
-        response.end();	
+        response.write(JSON.stringify(jsonobject), "utf8");
+        response.end();
         //console.log("Serve here")
         //console.log("Serve here")
 
 
     }
     }
@@ -72,7 +68,7 @@ function startVWF() {
         try {
         try {
             serve(request, response);
             serve(request, response);
             // vwf.Serve( request, response );
             // vwf.Serve( request, response );
-           
+
         } catch (e) {
         } catch (e) {
             response.writeHead(500, {
             response.writeHead(500, {
                 "Content-Type": "text/plain"
                 "Content-Type": "text/plain"
@@ -84,33 +80,18 @@ function startVWF() {
 
 
     consoleNotice('LogLevel = ' + global.logLevel);
     consoleNotice('LogLevel = ' + global.logLevel);
 
 
-    //consoleNotice( 'Serving VWF support files from ' + global.vwfRoot );
-
-    if (argv.nocache) {
-        FileCache.enabled = false;
-        consoleNotice('server cache disabled');
-    }
-
-    var ssl = (argv.s || argv.ssl);
-    var pass = ((argv.w) ? (argv.w) : undefined);
-    var sslOptions = {
-        key: ((argv.k || argv.key) ? fs.readFileSync(argv.k || argv.key) : undefined),
-        cert: ((argv.c || argv.cert) ? fs.readFileSync(argv.c || argv.cert) : undefined),
-        ca: ( ( argv.t || argv.ca ) ? fs.readFileSync( argv.t || argv.ca ) : undefined ),
-        passphrase: JSON.stringify(pass)
-    };
-
     //create the server
     //create the server
-    var port = ((argv.p || argv.port) ? (argv.p || argv.port) : 3002);
 
 
-    var srv = ssl ? https.createServer(sslOptions, OnRequest).listen(port) : http.createServer(OnRequest).listen(port);
-    consoleNotice('Serving on port ' + port);
+    var conf = config.parseConfigOptions();
+
+    var srv = conf.ssl ? https.createServer(conf.sslOptions, OnRequest).listen(conf.port) : http.createServer(OnRequest).listen(conf.port);
+    consoleNotice('Serving on port ' + conf.port);
 
 
-    var socketManager = sio.listen(srv, 
-        { 
-        log: false
-        //pingTimeout: 3600 
-    });
+    var socketManager = sio.listen(srv,
+        {
+            log: false
+            //pingTimeout: 3600 
+        });
 
 
     socketManager.set('transports', ['websocket']);
     socketManager.set('transports', ['websocket']);
     socketManager.sockets.on('connection', reflector.OnConnection);
     socketManager.sockets.on('connection', reflector.OnConnection);

+ 205 - 222
package-lock.json

@@ -41,12 +41,6 @@
       "resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz",
       "resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz",
       "integrity": "sha1-MasayLEpNjRj41s+u2n038+6eUc="
       "integrity": "sha1-MasayLEpNjRj41s+u2n038+6eUc="
     },
     },
-    "balanced-match": {
-      "version": "1.0.0",
-      "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
-      "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
-      "dev": true
-    },
     "base64-arraybuffer": {
     "base64-arraybuffer": {
       "version": "0.1.5",
       "version": "0.1.5",
       "resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.1.5.tgz",
       "resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.1.5.tgz",
@@ -70,32 +64,60 @@
       "resolved": "https://registry.npmjs.org/blob/-/blob-0.0.4.tgz",
       "resolved": "https://registry.npmjs.org/blob/-/blob-0.0.4.tgz",
       "integrity": "sha1-vPEwUspURj8w+fx+lbmkdjCpSSE="
       "integrity": "sha1-vPEwUspURj8w+fx+lbmkdjCpSSE="
     },
     },
-    "brace-expansion": {
-      "version": "1.1.8",
-      "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz",
-      "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=",
-      "dev": true,
-      "requires": {
-        "balanced-match": "^1.0.0",
-        "concat-map": "0.0.1"
-      }
-    },
-    "browser-stdout": {
-      "version": "1.3.0",
-      "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.0.tgz",
-      "integrity": "sha1-81HTKWnTL6XXpVZxVCY9korjvR8=",
-      "dev": true
-    },
     "callsite": {
     "callsite": {
       "version": "1.0.0",
       "version": "1.0.0",
       "resolved": "https://registry.npmjs.org/callsite/-/callsite-1.0.0.tgz",
       "resolved": "https://registry.npmjs.org/callsite/-/callsite-1.0.0.tgz",
       "integrity": "sha1-KAOY5dZkvXQDi28JBRU+borxvCA="
       "integrity": "sha1-KAOY5dZkvXQDi28JBRU+borxvCA="
     },
     },
-    "commander": {
-      "version": "2.11.0",
-      "resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz",
-      "integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==",
-      "dev": true
+    "color": {
+      "version": "3.0.0",
+      "resolved": "https://registry.npmjs.org/color/-/color-3.0.0.tgz",
+      "integrity": "sha512-jCpd5+s0s0t7p3pHQKpnJ0TpQKKdleP71LWcA0aqiljpiuAkOSUFN/dyH8ZwF0hRmFlrIuRhufds1QyEP9EB+w==",
+      "requires": {
+        "color-convert": "^1.9.1",
+        "color-string": "^1.5.2"
+      }
+    },
+    "color-convert": {
+      "version": "1.9.3",
+      "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
+      "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
+      "requires": {
+        "color-name": "1.1.3"
+      }
+    },
+    "color-name": {
+      "version": "1.1.3",
+      "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
+      "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
+    },
+    "color-string": {
+      "version": "1.5.3",
+      "resolved": "https://registry.npmjs.org/color-string/-/color-string-1.5.3.tgz",
+      "integrity": "sha512-dC2C5qeWoYkxki5UAXapdjqO672AM4vZuPGRQfO8b5HKuKGBbKWpITyDYN7TOFKvRW7kOgAn3746clDBMDJyQw==",
+      "requires": {
+        "color-name": "^1.0.0",
+        "simple-swizzle": "^0.2.2"
+      }
+    },
+    "colornames": {
+      "version": "1.1.1",
+      "resolved": "https://registry.npmjs.org/colornames/-/colornames-1.1.1.tgz",
+      "integrity": "sha1-+IiQMGhcfE/54qVZ9Qd+t2qBb5Y="
+    },
+    "colors": {
+      "version": "1.3.2",
+      "resolved": "https://registry.npmjs.org/colors/-/colors-1.3.2.tgz",
+      "integrity": "sha512-rhP0JSBGYvpcNQj4s5AdShMeE5ahMop96cTeDl/v9qQQm2fYClE2QXZRi8wLzc+GmXSxdIqqbOIAhyObEXDbfQ=="
+    },
+    "colorspace": {
+      "version": "1.1.1",
+      "resolved": "https://registry.npmjs.org/colorspace/-/colorspace-1.1.1.tgz",
+      "integrity": "sha512-pI3btWyiuz7Ken0BWh9Elzsmv2bM9AhA7psXib4anUXy/orfZ/E0MbQwhSOG/9L8hLlalqrU0UhOuqxW1YjmVw==",
+      "requires": {
+        "color": "3.0.x",
+        "text-hex": "1.0.x"
+      }
     },
     },
     "component-bind": {
     "component-bind": {
       "version": "1.0.0",
       "version": "1.0.0",
@@ -112,17 +134,16 @@
       "resolved": "https://registry.npmjs.org/component-inherit/-/component-inherit-0.0.3.tgz",
       "resolved": "https://registry.npmjs.org/component-inherit/-/component-inherit-0.0.3.tgz",
       "integrity": "sha1-ZF/ErfWLcrZJ1crmUTVhnbJv8UM="
       "integrity": "sha1-ZF/ErfWLcrZJ1crmUTVhnbJv8UM="
     },
     },
-    "concat-map": {
-      "version": "0.0.1",
-      "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
-      "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
-      "dev": true
-    },
     "cookie": {
     "cookie": {
       "version": "0.3.1",
       "version": "0.3.1",
       "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz",
       "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz",
       "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s="
       "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s="
     },
     },
+    "core-util-is": {
+      "version": "1.0.2",
+      "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
+      "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
+    },
     "crypto": {
     "crypto": {
       "version": "1.0.1",
       "version": "1.0.1",
       "resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz",
       "resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz",
@@ -136,11 +157,23 @@
         "ms": "2.0.0"
         "ms": "2.0.0"
       }
       }
     },
     },
-    "diff": {
-      "version": "3.3.1",
-      "resolved": "https://registry.npmjs.org/diff/-/diff-3.3.1.tgz",
-      "integrity": "sha512-MKPHZDMB0o6yHyDryUOScqZibp914ksXwAMYMTHj6KO8UeKsRYNJD3oNCKjTqZon+V488P7N/HzXF8t7ZR95ww==",
-      "dev": true
+    "diagnostics": {
+      "version": "1.1.1",
+      "resolved": "https://registry.npmjs.org/diagnostics/-/diagnostics-1.1.1.tgz",
+      "integrity": "sha512-8wn1PmdunLJ9Tqbx+Fx/ZEuHfJf4NKSN2ZBj7SJC/OWRWha843+WsTjqMe1B5E3p28jqBlp+mJ2fPVxPyNgYKQ==",
+      "requires": {
+        "colorspace": "1.1.x",
+        "enabled": "1.0.x",
+        "kuler": "1.0.x"
+      }
+    },
+    "enabled": {
+      "version": "1.0.2",
+      "resolved": "https://registry.npmjs.org/enabled/-/enabled-1.0.2.tgz",
+      "integrity": "sha1-ll9lE9LC0cX0ZStkouM5ZGf8L5M=",
+      "requires": {
+        "env-variable": "0.0.x"
+      }
     },
     },
     "engine.io": {
     "engine.io": {
       "version": "3.2.0",
       "version": "3.2.0",
@@ -185,37 +218,20 @@
         "has-binary2": "~1.0.2"
         "has-binary2": "~1.0.2"
       }
       }
     },
     },
-    "escape-string-regexp": {
-      "version": "1.0.5",
-      "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
-      "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
-      "dev": true
+    "env-variable": {
+      "version": "0.0.5",
+      "resolved": "https://registry.npmjs.org/env-variable/-/env-variable-0.0.5.tgz",
+      "integrity": "sha512-zoB603vQReOFvTg5xMl9I1P2PnHsHQQKTEowsKKD7nseUfJq6UWzK+4YtlWUO1nhiQUxe6XMkk+JleSZD1NZFA=="
     },
     },
-    "fs.realpath": {
-      "version": "1.0.0",
-      "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
-      "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
-      "dev": true
-    },
-    "glob": {
-      "version": "7.1.2",
-      "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
-      "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==",
-      "dev": true,
-      "requires": {
-        "fs.realpath": "^1.0.0",
-        "inflight": "^1.0.4",
-        "inherits": "2",
-        "minimatch": "^3.0.4",
-        "once": "^1.3.0",
-        "path-is-absolute": "^1.0.0"
-      }
+    "fast-safe-stringify": {
+      "version": "2.0.6",
+      "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.0.6.tgz",
+      "integrity": "sha512-q8BZ89jjc+mz08rSxROs8VsrBBcn1SIw1kq9NjolL509tkABRk9io01RAjSaEv1Xb2uFLt8VtRiZbGp5H8iDtg=="
     },
     },
-    "growl": {
-      "version": "1.10.3",
-      "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.3.tgz",
-      "integrity": "sha512-hKlsbA5Vu3xsh1Cg3J7jSmX/WaW6A5oBeqzM88oNbCRQFz+zUaXm6yxS4RVytp1scBoJzSYl4YAEOQIt6O8V1Q==",
-      "dev": true
+    "fecha": {
+      "version": "2.3.3",
+      "resolved": "https://registry.npmjs.org/fecha/-/fecha-2.3.3.tgz",
+      "integrity": "sha512-lUGBnIamTAwk4znq5BcqsDaxSmZ9nDVJaij6NvRt/Tg4R69gERA+otPKbS86ROw9nxVMw2/mp1fnaiWqbs6Sdg=="
     },
     },
     "has-binary2": {
     "has-binary2": {
       "version": "1.0.3",
       "version": "1.0.3",
@@ -230,49 +246,63 @@
       "resolved": "https://registry.npmjs.org/has-cors/-/has-cors-1.1.0.tgz",
       "resolved": "https://registry.npmjs.org/has-cors/-/has-cors-1.1.0.tgz",
       "integrity": "sha1-XkdHk/fqmEPRu5nCPu9J/xJv/zk="
       "integrity": "sha1-XkdHk/fqmEPRu5nCPu9J/xJv/zk="
     },
     },
-    "has-flag": {
-      "version": "2.0.0",
-      "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz",
-      "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=",
-      "dev": true
-    },
-    "he": {
-      "version": "1.1.1",
-      "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz",
-      "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=",
-      "dev": true
-    },
     "indexof": {
     "indexof": {
       "version": "0.0.1",
       "version": "0.0.1",
       "resolved": "https://registry.npmjs.org/indexof/-/indexof-0.0.1.tgz",
       "resolved": "https://registry.npmjs.org/indexof/-/indexof-0.0.1.tgz",
       "integrity": "sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10="
       "integrity": "sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10="
     },
     },
-    "inflight": {
-      "version": "1.0.6",
-      "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
-      "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
-      "dev": true,
-      "requires": {
-        "once": "^1.3.0",
-        "wrappy": "1"
-      }
-    },
     "inherits": {
     "inherits": {
       "version": "2.0.3",
       "version": "2.0.3",
       "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
       "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
-      "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=",
-      "dev": true
+      "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
+    },
+    "is-arrayish": {
+      "version": "0.3.2",
+      "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz",
+      "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ=="
+    },
+    "is-stream": {
+      "version": "1.1.0",
+      "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
+      "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ="
     },
     },
     "isarray": {
     "isarray": {
       "version": "2.0.1",
       "version": "2.0.1",
       "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.1.tgz",
       "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.1.tgz",
       "integrity": "sha1-o32U7ZzaLVmGXJ92/llu4fM4dB4="
       "integrity": "sha1-o32U7ZzaLVmGXJ92/llu4fM4dB4="
     },
     },
+    "kuler": {
+      "version": "1.0.1",
+      "resolved": "https://registry.npmjs.org/kuler/-/kuler-1.0.1.tgz",
+      "integrity": "sha512-J9nVUucG1p/skKul6DU3PUZrhs0LPulNaeUOox0IyXDi8S4CztTHs1gQphhuZmzXG7VOQSf6NJfKuzteQLv9gQ==",
+      "requires": {
+        "colornames": "^1.1.1"
+      }
+    },
     "lodash": {
     "lodash": {
       "version": "4.17.10",
       "version": "4.17.10",
       "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
       "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
       "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg=="
       "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg=="
     },
     },
+    "logform": {
+      "version": "1.10.0",
+      "resolved": "https://registry.npmjs.org/logform/-/logform-1.10.0.tgz",
+      "integrity": "sha512-em5ojIhU18fIMOw/333mD+ZLE2fis0EzXl1ZwHx4iQzmpQi6odNiY/t+ITNr33JZhT9/KEaH+UPIipr6a9EjWg==",
+      "requires": {
+        "colors": "^1.2.1",
+        "fast-safe-stringify": "^2.0.4",
+        "fecha": "^2.3.3",
+        "ms": "^2.1.1",
+        "triple-beam": "^1.2.0"
+      },
+      "dependencies": {
+        "ms": {
+          "version": "2.1.1",
+          "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
+          "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg=="
+        }
+      }
+    },
     "mime": {
     "mime": {
       "version": "2.3.1",
       "version": "2.3.1",
       "resolved": "https://registry.npmjs.org/mime/-/mime-2.3.1.tgz",
       "resolved": "https://registry.npmjs.org/mime/-/mime-2.3.1.tgz",
@@ -291,66 +321,11 @@
         "mime-db": "~1.36.0"
         "mime-db": "~1.36.0"
       }
       }
     },
     },
-    "minimatch": {
-      "version": "3.0.4",
-      "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
-      "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
-      "dev": true,
-      "requires": {
-        "brace-expansion": "^1.1.7"
-      }
-    },
     "minimist": {
     "minimist": {
       "version": "0.0.10",
       "version": "0.0.10",
       "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz",
       "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz",
       "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8="
       "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8="
     },
     },
-    "mkdirp": {
-      "version": "0.5.1",
-      "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
-      "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
-      "dev": true,
-      "requires": {
-        "minimist": "0.0.8"
-      },
-      "dependencies": {
-        "minimist": {
-          "version": "0.0.8",
-          "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
-          "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
-          "dev": true
-        }
-      }
-    },
-    "mocha": {
-      "version": "5.0.0",
-      "resolved": "https://registry.npmjs.org/mocha/-/mocha-5.0.0.tgz",
-      "integrity": "sha512-ukB2dF+u4aeJjc6IGtPNnJXfeby5d4ZqySlIBT0OEyva/DrMjVm5HkQxKnHDLKEfEQBsEnwTg9HHhtPHJdTd8w==",
-      "dev": true,
-      "requires": {
-        "browser-stdout": "1.3.0",
-        "commander": "2.11.0",
-        "debug": "3.1.0",
-        "diff": "3.3.1",
-        "escape-string-regexp": "1.0.5",
-        "glob": "7.1.2",
-        "growl": "1.10.3",
-        "he": "1.1.1",
-        "mkdirp": "0.5.1",
-        "supports-color": "4.4.0"
-      },
-      "dependencies": {
-        "debug": {
-          "version": "3.1.0",
-          "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
-          "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
-          "dev": true,
-          "requires": {
-            "ms": "2.0.0"
-          }
-        }
-      }
-    },
     "ms": {
     "ms": {
       "version": "2.0.0",
       "version": "2.0.0",
       "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
       "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
@@ -366,14 +341,10 @@
       "resolved": "https://registry.npmjs.org/object-component/-/object-component-0.0.3.tgz",
       "resolved": "https://registry.npmjs.org/object-component/-/object-component-0.0.3.tgz",
       "integrity": "sha1-8MaapQ78lbhmwYb0AKM3acsvEpE="
       "integrity": "sha1-8MaapQ78lbhmwYb0AKM3acsvEpE="
     },
     },
-    "once": {
-      "version": "1.4.0",
-      "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
-      "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
-      "dev": true,
-      "requires": {
-        "wrappy": "1"
-      }
+    "one-time": {
+      "version": "0.0.4",
+      "resolved": "https://registry.npmjs.org/one-time/-/one-time-0.0.4.tgz",
+      "integrity": "sha1-+M33eISCb+Tf+T46nMN7HkSAdC4="
     },
     },
     "optimist": {
     "optimist": {
       "version": "0.6.1",
       "version": "0.6.1",
@@ -400,71 +371,45 @@
         "better-assert": "~1.0.0"
         "better-assert": "~1.0.0"
       }
       }
     },
     },
-    "path-is-absolute": {
-      "version": "1.0.1",
-      "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
-      "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
-      "dev": true
-    },
-    "safe-buffer": {
-      "version": "5.1.2",
-      "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
-      "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
-    },
-    "should": {
-      "version": "13.2.1",
-      "resolved": "https://registry.npmjs.org/should/-/should-13.2.1.tgz",
-      "integrity": "sha512-l+/NwEMO+DcstsHEwPHRHzC9j4UOE3VQwJGcMWSsD/vqpqHbnQ+1iSHy64Ihmmjx1uiRPD9pFadTSc3MJtXAgw==",
-      "dev": true,
-      "requires": {
-        "should-equal": "^2.0.0",
-        "should-format": "^3.0.3",
-        "should-type": "^1.4.0",
-        "should-type-adaptors": "^1.0.1",
-        "should-util": "^1.0.0"
-      }
-    },
-    "should-equal": {
+    "process-nextick-args": {
       "version": "2.0.0",
       "version": "2.0.0",
-      "resolved": "https://registry.npmjs.org/should-equal/-/should-equal-2.0.0.tgz",
-      "integrity": "sha512-ZP36TMrK9euEuWQYBig9W55WPC7uo37qzAEmbjHz4gfyuXrEUgF8cUvQVO+w+d3OMfPvSRQJ22lSm8MQJ43LTA==",
-      "dev": true,
-      "requires": {
-        "should-type": "^1.4.0"
-      }
+      "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz",
+      "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw=="
     },
     },
-    "should-format": {
-      "version": "3.0.3",
-      "resolved": "https://registry.npmjs.org/should-format/-/should-format-3.0.3.tgz",
-      "integrity": "sha1-m/yPdPo5IFxT04w01xcwPidxJPE=",
-      "dev": true,
+    "readable-stream": {
+      "version": "2.3.6",
+      "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz",
+      "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==",
       "requires": {
       "requires": {
-        "should-type": "^1.3.0",
-        "should-type-adaptors": "^1.0.1"
+        "core-util-is": "~1.0.0",
+        "inherits": "~2.0.3",
+        "isarray": "~1.0.0",
+        "process-nextick-args": "~2.0.0",
+        "safe-buffer": "~5.1.1",
+        "string_decoder": "~1.1.1",
+        "util-deprecate": "~1.0.1"
+      },
+      "dependencies": {
+        "isarray": {
+          "version": "1.0.0",
+          "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
+          "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
+        }
       }
       }
     },
     },
-    "should-type": {
-      "version": "1.4.0",
-      "resolved": "https://registry.npmjs.org/should-type/-/should-type-1.4.0.tgz",
-      "integrity": "sha1-B1bYzoRt/QmEOmlHcZ36DUz/XPM=",
-      "dev": true
+    "safe-buffer": {
+      "version": "5.1.2",
+      "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
+      "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
     },
     },
-    "should-type-adaptors": {
-      "version": "1.1.0",
-      "resolved": "https://registry.npmjs.org/should-type-adaptors/-/should-type-adaptors-1.1.0.tgz",
-      "integrity": "sha512-JA4hdoLnN+kebEp2Vs8eBe9g7uy0zbRo+RMcU0EsNy+R+k049Ki+N5tT5Jagst2g7EAja+euFuoXFCa8vIklfA==",
-      "dev": true,
+    "simple-swizzle": {
+      "version": "0.2.2",
+      "resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz",
+      "integrity": "sha1-pNprY1/8zMoz9w0Xy5JZLeleVXo=",
       "requires": {
       "requires": {
-        "should-type": "^1.3.0",
-        "should-util": "^1.0.0"
+        "is-arrayish": "^0.3.1"
       }
       }
     },
     },
-    "should-util": {
-      "version": "1.0.0",
-      "resolved": "https://registry.npmjs.org/should-util/-/should-util-1.0.0.tgz",
-      "integrity": "sha1-yYzaN0qmsZDfi6h8mInCtNtiAGM=",
-      "dev": true
-    },
     "socket.io": {
     "socket.io": {
       "version": "2.1.1",
       "version": "2.1.1",
       "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-2.1.1.tgz",
       "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-2.1.1.tgz",
@@ -514,36 +459,74 @@
         "isarray": "2.0.1"
         "isarray": "2.0.1"
       }
       }
     },
     },
-    "supports-color": {
-      "version": "4.4.0",
-      "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz",
-      "integrity": "sha512-rKC3+DyXWgK0ZLKwmRsrkyHVZAjNkfzeehuFWdGGcqGDTZFH73+RH6S/RDAAxl9GusSjZSUWYLmT9N5pzXFOXQ==",
-      "dev": true,
+    "stack-trace": {
+      "version": "0.0.10",
+      "resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz",
+      "integrity": "sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA="
+    },
+    "string_decoder": {
+      "version": "1.1.1",
+      "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
+      "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
       "requires": {
       "requires": {
-        "has-flag": "^2.0.0"
+        "safe-buffer": "~5.1.0"
       }
       }
     },
     },
+    "text-hex": {
+      "version": "1.0.0",
+      "resolved": "https://registry.npmjs.org/text-hex/-/text-hex-1.0.0.tgz",
+      "integrity": "sha512-uuVGNWzgJ4yhRaNSiubPY7OjISw4sw4E5Uv0wbjp+OzcbmVU/rsT8ujgcXJhn9ypzsgr5vlzpPqP+MBBKcGvbg=="
+    },
     "to-array": {
     "to-array": {
       "version": "0.1.4",
       "version": "0.1.4",
       "resolved": "https://registry.npmjs.org/to-array/-/to-array-0.1.4.tgz",
       "resolved": "https://registry.npmjs.org/to-array/-/to-array-0.1.4.tgz",
       "integrity": "sha1-F+bBH3PdTz10zaek/zI46a2b+JA="
       "integrity": "sha1-F+bBH3PdTz10zaek/zI46a2b+JA="
     },
     },
+    "triple-beam": {
+      "version": "1.3.0",
+      "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.3.0.tgz",
+      "integrity": "sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw=="
+    },
     "ultron": {
     "ultron": {
       "version": "1.1.1",
       "version": "1.1.1",
       "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz",
       "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz",
       "integrity": "sha512-UIEXBNeYmKptWH6z8ZnqTeS8fV74zG0/eRU9VGkpzz+LIJNs8W/zM/L+7ctCkRrgbNnnR0xxw4bKOr0cW0N0Og=="
       "integrity": "sha512-UIEXBNeYmKptWH6z8ZnqTeS8fV74zG0/eRU9VGkpzz+LIJNs8W/zM/L+7ctCkRrgbNnnR0xxw4bKOr0cW0N0Og=="
     },
     },
+    "util-deprecate": {
+      "version": "1.0.2",
+      "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
+      "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
+    },
+    "winston": {
+      "version": "3.1.0",
+      "resolved": "https://registry.npmjs.org/winston/-/winston-3.1.0.tgz",
+      "integrity": "sha512-FsQfEE+8YIEeuZEYhHDk5cILo1HOcWkGwvoidLrDgPog0r4bser1lEIOco2dN9zpDJ1M88hfDgZvxe5z4xNcwg==",
+      "requires": {
+        "async": "^2.6.0",
+        "diagnostics": "^1.1.1",
+        "is-stream": "^1.1.0",
+        "logform": "^1.9.1",
+        "one-time": "0.0.4",
+        "readable-stream": "^2.3.6",
+        "stack-trace": "0.0.x",
+        "triple-beam": "^1.3.0",
+        "winston-transport": "^4.2.0"
+      }
+    },
+    "winston-transport": {
+      "version": "4.2.0",
+      "resolved": "https://registry.npmjs.org/winston-transport/-/winston-transport-4.2.0.tgz",
+      "integrity": "sha512-0R1bvFqxSlK/ZKTH86nymOuKv/cT1PQBMuDdA7k7f0S9fM44dNH6bXnuxwXPrN8lefJgtZq08BKdyZ0DZIy/rg==",
+      "requires": {
+        "readable-stream": "^2.3.6",
+        "triple-beam": "^1.2.0"
+      }
+    },
     "wordwrap": {
     "wordwrap": {
       "version": "0.0.3",
       "version": "0.0.3",
       "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz",
       "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz",
       "integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc="
       "integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc="
     },
     },
-    "wrappy": {
-      "version": "1.0.2",
-      "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
-      "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
-      "dev": true
-    },
     "ws": {
     "ws": {
       "version": "3.3.3",
       "version": "3.3.3",
       "resolved": "https://registry.npmjs.org/ws/-/ws-3.3.3.tgz",
       "resolved": "https://registry.npmjs.org/ws/-/ws-3.3.3.tgz",

+ 8 - 11
package.json

@@ -1,18 +1,18 @@
 {
 {
   "name": "lcs-reflector",
   "name": "lcs-reflector",
-  "description": "LiveCoding.Space reflector",
+  "description": "LiveCoding.space reflector",
   "version": "0.0.2",
   "version": "0.0.2",
   "author": "Nikolai Suslov",
   "author": "Nikolai Suslov",
   "scripts": {
   "scripts": {
-    "start": "node ./node-server.js -p 3002",
-    "startSSL": "node ./node-server.js -p 3002 -s -k ./certs/server-key.pem -c ./certs/server-crt.pem -t ./certs/ca-crt.pem -w 12345",
+    "start": "node ./index.js",
+    "startSSL": "node ./index.js -p 3001 -s -k ./certs/server-key.pem -c ./certs/server-crt.pem -t ./certs/ca-crt.pem -w 12345",
     "test": "echo \"Error: no test specified\" && exit 1"
     "test": "echo \"Error: no test specified\" && exit 1"
   },
   },
   "directories": {
   "directories": {
     "lib": "lib"
     "lib": "lib"
   },
   },
-  "main": "node-server.js",
-  "homepage": "http://livecoding.space",
+  "main": "index.js",
+  "homepage": "https://livecoding.space",
   "repository": {
   "repository": {
     "type": "git",
     "type": "git",
     "url": "https://github.com/NikolaySuslov/lcs-reflector.git"
     "url": "https://github.com/NikolaySuslov/lcs-reflector.git"
@@ -23,11 +23,8 @@
     "socket.io-client": "^2.1.1",
     "socket.io-client": "^2.1.1",
     "async": "2.6.1",
     "async": "2.6.1",
     "mime": "2.3.1",
     "mime": "2.3.1",
-    "optimist": "0.6.1"
+    "optimist": "0.6.1",
+    "winston": "3.1.0"
   },
   },
-  "devDependencies": {
-    "mocha": "x.x.x",
-    "should": "x.x.x"
-  },
-  "license": "Apache"
+  "license": "MIT"
 }
 }

+ 28 - 0
server/logger.js

@@ -0,0 +1,28 @@
+// Copyright (c) 2018 Nikolai Suslov
+// Krestianstvo.org MIT license (https://github.com/NikolaySuslov/lcs-reflector/blob/master/LICENSE.md)
+
+var winston = require('winston');
+
+const logger = winston.createLogger({
+    level: 'info',
+    format: winston.format.json(),
+    transports: [
+      //
+      // - Write to all logs with level `info` and below to `combined.log` 
+      // - Write all logs error (and below) to `error.log`.
+      //
+      new winston.transports.File({ filename: 'error.log', level: 'error' }),
+      //new winston.transports.File({ filename: 'combined.log' })
+    ]
+  });
+  
+  //
+  // If we're not in production then log to the `console` with the format:
+  // `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
+  // 
+  if (process.env.NODE_ENV !== 'production') {
+    logger.add(new winston.transports.Console({
+      format: winston.format.simple()
+    }));
+  }
+module.exports = logger;

+ 82 - 0
server/readConfig.js

@@ -0,0 +1,82 @@
+// Copyright (c) 2018 Nikolai Suslov
+// Krestianstvo.org MIT license (https://github.com/NikolaySuslov/lcs-reflector/blob/master/LICENSE.md)
+
+var fs = require('fs'),
+    argv = require('optimist').argv,
+    logger = require('./logger')
+
+function parseConfigOptions() {
+
+  let conf = {
+      sslOptions: {}
+  }
+
+  var ssl = (argv.s || argv.ssl);
+  var pass = ((argv.w) ? (argv.w) : undefined);
+  var sslOptions = {
+      key: ((argv.k || argv.key) ? fs.readFileSync(argv.k || argv.key) : undefined),
+      cert: ((argv.c || argv.cert) ? fs.readFileSync(argv.c || argv.cert) : undefined),
+      ca: ((argv.t || argv.ca) ? fs.readFileSync(argv.t || argv.ca) : undefined),
+      passphrase: JSON.stringify(pass)
+  };
+  conf.sslOptions = sslOptions;
+
+  var port = ((argv.p || argv.port) ? (argv.p || argv.port) : undefined);
+
+  if (!ssl) {
+      if (global.configuration.ssl === undefined)
+          ssl = false;
+
+      if (global.configuration.ssl) {
+          ssl = true;
+          if (global.configuration.sslKey !== "")
+              conf.sslOptions.key = fs.readFileSync(global.configuration.sslKey)
+
+          if (global.configuration.sslCert !== "")
+              conf.sslOptions.cert = fs.readFileSync(global.configuration.sslCert)
+
+          if (global.configuration.sslCA !== "")
+              conf.sslOptions.ca = fs.readFileSync(global.configuration.sslCA)
+
+          if (global.configuration.certPwd !== "")
+              conf.sslOptions.passphrase = JSON.stringify(global.configuration.certPwd)
+      }
+  }
+
+  if (!port) {
+      if (global.configuration.port === undefined)
+          global.configuration.port = 3001 //by default
+
+      if (global.configuration.port)
+          port = global.configuration.port
+  }
+
+
+  conf.ssl = ssl;
+  conf.port = port
+
+  return conf
+}
+
+function readConfigFile() {
+  var configSettings;
+  var p = process.argv.indexOf('-config');
+
+  //This is a bit ugly, but it does beat putting a ton of if/else statements everywhere
+  var config = p >= 0 ? (process.argv[p + 1]) : './config.json';
+  logger.warn('loading config from ' + config);
+  //start the DAL, load configuration file
+  try {
+      configSettings = JSON.parse(fs.readFileSync(config).toString());
+      logger.info('Configuration read.');
+  } catch (e) {
+      configSettings = {};
+      logger.error(e.message);
+      logger.error('Could not read config file. Loading defaults.');
+  }
+  //save configuration into global scope so other modules can use.
+  global.configuration = configSettings;
+}
+
+exports.parseConfigOptions = parseConfigOptions;
+exports.readConfigFile = readConfigFile;