Browse Source

add --https option. Fixes #31

master
Lloyd Brookes 9 years ago
parent
commit
869a725fd3
  1. 8
      bin/cli.js
  2. 4
      lib/cli-options.js
  3. 20
      ssl/127.0.0.1.crt
  4. 27
      ssl/127.0.0.1.key

8
bin/cli.js

@ -9,6 +9,7 @@ const path = require('path')
const os = require('os') const os = require('os')
const arrayify = require('array-back') const arrayify = require('array-back')
const t = require('typical') const t = require('typical')
const flatten = require('reduce-flatten')
const cli = commandLineArgs(cliOptions.definitions) const cli = commandLineArgs(cliOptions.definitions)
const usage = cli.getUsage(cliOptions.usageData) const usage = cli.getUsage(cliOptions.usageData)
@ -47,6 +48,11 @@ const app = localWebServer({
mocks: options.server.mocks mocks: options.server.mocks
}) })
if (options.server.https) {
options.server.key = path.resolve(__dirname, '..', 'ssl', '127.0.0.1.key')
options.server.cert = path.resolve(__dirname, '..', 'ssl', '127.0.0.1.crt')
}
let isHttps = false let isHttps = false
if (options.server.key && options.server.cert) { if (options.server.key && options.server.cert) {
const https = require('https') const https = require('https')
@ -72,7 +78,7 @@ function stop (msgs, exitCode) {
function onServerUp () { function onServerUp () {
let ipList = Object.keys(os.networkInterfaces()) let ipList = Object.keys(os.networkInterfaces())
.map(key => os.networkInterfaces()[key]) .map(key => os.networkInterfaces()[key])
.reduce((prev, curr) => prev = prev.concat(curr), [])
.reduce(flatten, [])
.filter(iface => iface.family === 'IPv4') .filter(iface => iface.family === 'IPv4')
ipList.unshift({ address: os.hostname() }) ipList.unshift({ address: os.hostname() })
ipList = ipList ipList = ipList

4
lib/cli-options.js

@ -41,6 +41,10 @@ module.exports = {
description: 'SSL cert. Supply along with --key to launch a https server.' description: 'SSL cert. Supply along with --key to launch a https server.'
}, },
{ {
name: 'https', type: Boolean, group: 'server',
description: 'Enable HTTPS using a built-in key and cert, registered to the domain 127.0.0.1.'
},
{
name: 'verbose', type: Boolean, name: 'verbose', type: Boolean,
description: 'Verbose output, useful for debugging.', group: 'server' description: 'Verbose output, useful for debugging.', group: 'server'
}, },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