+const argv = require('minimist')(process.argv.slice(2), {
+ string: [ 'ca-cert', 'ca-key', 'config', 'client-js', 'host-js', 'electron', 'port' ],
+ boolean: [ 'remote-host' ],
+ alias: { c: 'config',
+ j: 'client-js',
+ J: 'host-js',
+ C: 'ca-cert',
+ K: 'ca-key',
+ e: 'electron',
+ r: 'remote-host',
+ p: 'port'
+ },
+ default: { config: undefined,
+ 'client-js': 'client.js',
+ 'host-js': 'host.js',
+ 'ca-cert': 'stunnel.cert',
+ 'ca-key': 'stunnel.key',
+ 'remote-host': true,
+ 'port': 2443
+ },
+ stopEarly: true,
+ unknown: (opt) => {
+ console.log(process.argv.join(" ") + '\nUnknown operator: ' + opt + `
+Usage: strapp [OPTION]...
+Route https connections from a hardware port to a remote host, and initiate
+peer-to-peer connection with clients.
+
+CONFIG
+ -c, --config=path Configuration file to use (/etc/strapp.conf)
+ - overridden by command line opts
+ -j, --client-js=path Path to the client Strapp code (./strapp-client.js)
+ -J, --host-js=path Path to the host Strapp code (./strapp-host.js)
+ -C, --ca-cert=path Accessible location of the CA Cert (./stunnel.cert)
+ -K, --ca-key=path Accessible location of the CA Key (./stunnel.key)
+ -p, --port=number The local port to bind HTTPS listener to (2443)
+
+ROUTING
+ -e, --electron=route Route to the local electron user (nil)
+ - enables optional electron dependency
+ -d, --dedicated=route Route all incoming connections to this route (nil)
+ - used in conjunction with '-e=my_route'
+
+(c)2017 jk software
+`)
+ process.exit()
+ }
+})
+
+//TODO: if (argv['config'] !== undefined), read and apply to argv without overwrite
+if (argv['www-path'] == undefined)
+ argv['www-path'] = 'www'
+else if (String(argv['www-path']).endsWith('/'))
+ argv['www-path'] = argv['www-path'].slice(0,-1)
+
+const routerOpts = {
+ key: fs.readFileSync(argv['ca-key']),
+ cert: fs.readFileSync(argv['ca-cert'])