|
@ -4,6 +4,7 @@ const ansi = require('ansi-escape-sequences') |
|
|
const path = require('path') |
|
|
const path = require('path') |
|
|
const CommandLineTool = require('command-line-tool') |
|
|
const CommandLineTool = require('command-line-tool') |
|
|
const flatten = require('reduce-flatten') |
|
|
const flatten = require('reduce-flatten') |
|
|
|
|
|
const arrayify = require('array-back') |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @module local-web-server |
|
|
* @module local-web-server |
|
@ -26,7 +27,7 @@ class LocalWebServer { |
|
|
const stored = loadConfig('local-web-server') |
|
|
const stored = loadConfig('local-web-server') |
|
|
|
|
|
|
|
|
/* manually scan for any --stack passed, as we may need to display stack options */ |
|
|
/* manually scan for any --stack passed, as we may need to display stack options */ |
|
|
const stackPaths = initOptions.stack || stored.stack || [] |
|
|
|
|
|
|
|
|
const stackPaths = arrayify(initOptions.stack || stored.stack) || [] |
|
|
const stackIndex = process.argv.indexOf('--stack') |
|
|
const stackIndex = process.argv.indexOf('--stack') |
|
|
if (stackIndex > -1) { |
|
|
if (stackIndex > -1) { |
|
|
for (var i = stackIndex + 1; i < process.argv.length; i++) { |
|
|
for (var i = stackIndex + 1; i < process.argv.length; i++) { |
|
@ -39,8 +40,10 @@ class LocalWebServer { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* load the stack */ |
|
|
|
|
|
|
|
|
/* if the user did not supply a stack, use the default */ |
|
|
if (!stackPaths.length) stackPaths.push(path.resolve(__dirname, '..', 'node_modules', 'local-web-server-default-stack')) |
|
|
if (!stackPaths.length) stackPaths.push(path.resolve(__dirname, '..', 'node_modules', 'local-web-server-default-stack')) |
|
|
|
|
|
|
|
|
|
|
|
/* load the stack */ |
|
|
const stackModules = stackPaths |
|
|
const stackModules = stackPaths |
|
|
.map(stackPath => loadStack(stackPath)) |
|
|
.map(stackPath => loadStack(stackPath)) |
|
|
.map(Middleware => new Middleware()) |
|
|
.map(Middleware => new Middleware()) |
|
@ -216,6 +219,7 @@ function getIPList () { |
|
|
*/ |
|
|
*/ |
|
|
function loadStack (modulePath) { |
|
|
function loadStack (modulePath) { |
|
|
let module |
|
|
let module |
|
|
|
|
|
if (isModule(modulePath)) return modulePath |
|
|
const tried = [] |
|
|
const tried = [] |
|
|
if (modulePath) { |
|
|
if (modulePath) { |
|
|
try { |
|
|
try { |
|
@ -237,7 +241,7 @@ function loadStack (modulePath) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (module) { |
|
|
if (module) { |
|
|
if (!(module.prototype.middleware || module.prototype.stack)) { |
|
|
|
|
|
|
|
|
if (!isModule(module)) { |
|
|
const insp = require('util').inspect(module, { depth: 3, colors: true }) |
|
|
const insp = require('util').inspect(module, { depth: 3, colors: true }) |
|
|
const msg = `Not valid Middleware at: ${insp}` |
|
|
const msg = `Not valid Middleware at: ${insp}` |
|
|
tool.halt(new Error(msg)) |
|
|
tool.halt(new Error(msg)) |
|
@ -249,4 +253,8 @@ function loadStack (modulePath) { |
|
|
return module |
|
|
return module |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function isModule (module) { |
|
|
|
|
|
return module.prototype.middleware || module.prototype.stack |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
module.exports = LocalWebServer |
|
|
module.exports = LocalWebServer |