Comparing version 2.0.0-6 to 2.0.0-7
50
index.js
@@ -31,2 +31,3 @@ const util = require('./lib/util') | ||
* @param [options.modulePrefix] {string} - An optional string to prefix to module names when loading middleware modules Defaults to 'lws-'. | ||
* @param [options.view] {object} - View instance. | ||
* @returns {Server} | ||
@@ -55,2 +56,3 @@ */ | ||
this.setConfig(config) | ||
this.setStack() | ||
} | ||
@@ -83,2 +85,25 @@ | ||
/** | ||
* Sets the middleware stack, loading plugins if supplied. | ||
*/ | ||
setStack () { | ||
const arrayify = require('array-back') | ||
const Stack = require('./lib/middleware-stack') | ||
let stack = arrayify(this.config.stack).slice() | ||
/* convert stack to type MiddlewareStack */ | ||
if (!(stack instanceof Stack)) { | ||
stack = Stack.from(stack, { | ||
paths: this.config.moduleDir, | ||
prefix: this.config.modulePrefix | ||
}) | ||
} | ||
util.propagate('verbose', stack, this) | ||
this.stack = stack | ||
} | ||
/** | ||
* Create a HTTP, HTTPS or HTTP2 server, depending on config. Returns the output of Node's standard http, https or http2 `.createServer()` method. | ||
* @returns {Server} | ||
*/ | ||
createServer () { | ||
@@ -141,23 +166,4 @@ if (this.server) throw new Error('server already created') | ||
/** | ||
* | ||
*/ | ||
loadMiddlewareStack () { | ||
const arrayify = require('array-back') | ||
let stack = arrayify(this.config.stack).slice() | ||
/* validate stack */ | ||
const Stack = require('./lib/middleware-stack') | ||
if (!(stack instanceof Stack)) { | ||
stack = Stack.from(stack, { | ||
paths: this.config.moduleDir, | ||
prefix: this.config.modulePrefix | ||
}) | ||
} | ||
this.stack = stack | ||
} | ||
/* Pipe server events into 'verbose' event stream */ | ||
_createServerEventStream () { | ||
_propagateServerEvents () { | ||
const write = (name, value) => { | ||
@@ -261,6 +267,4 @@ return () => { | ||
/* stream server events to a verbose event */ | ||
lws._createServerEventStream() | ||
lws._propagateServerEvents() | ||
lws.loadMiddlewareStack() | ||
/* attach middleware */ | ||
@@ -267,0 +271,0 @@ lws.useMiddlewareStack() |
@@ -52,3 +52,8 @@ const flatten = require('reduce-flatten') | ||
for (const MiddlewareClass of MiddlewareClasses) { | ||
stack.push(new MiddlewareClass()) | ||
const middleware = new MiddlewareClass() | ||
stack.push(middleware) | ||
/* extending EventEmitter is optional */ | ||
if (middleware.on) { | ||
middleware.on('verbose', (key, value) => stack.emit('verbose', key, value)) | ||
} | ||
} | ||
@@ -55,0 +60,0 @@ return stack |
{ | ||
"name": "lws", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
"version": "2.0.0-6", | ||
"version": "2.0.0-7", | ||
"description": "The modular web server for productive full-stack development", | ||
@@ -6,0 +6,0 @@ "repository": "https://github.com/lwsjs/lws.git", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
90811
924