Socket
Socket
Sign inDemoInstall

lws

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lws - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

24

index.js

@@ -6,3 +6,11 @@ const util = require('./lib/util')

/**
* An application shell for building a modular HTTP, HTTPS or HTTP2 local web server.
* A lean, modular web server for rapid full-stack development.
*
* Lws is an application core for quickly launching a local web server. Behaviour is added via plugins giving you full control over how requests are processed and responses created.
*
* * Supports HTTP, HTTPS and HTTP2.
* * Small and 100% personalisable. Load and use only the behaviour required by your project.
* * Attach a custom view to personalise how activity is visualised.
* * Programmatic and command-line APIs.
*
* @module lws

@@ -13,5 +21,5 @@ * @example

* middleware () {
* return (ctx, next) => {
* ctx.body = 'Hello!'
* next()
* return async (ctx, next) => {
* ctx.response.body = 'Hello!'
* await next()
* }

@@ -242,3 +250,3 @@ * }

socket.on('error', function (err) {
this.emit('verbose', 'server.socket.error', { err })
this.emit('verbose', 'server.socket.error', err)
})

@@ -264,2 +272,6 @@ })

server.on('error', err => {
this.emit('verbose', 'server.error', err)
})
/* emit memory usage stats every 30s */

@@ -292,3 +304,3 @@ const interval = setInterval(() => {

/* stream server events to a verbose event */
/* forward server events to the verbose event */
lws._propagateServerEvents()

@@ -295,0 +307,0 @@

@@ -6,6 +6,6 @@ /**

* class Greeter {
* middleware (options = {}) {
* return function (ctx, next) {
* ctx.body = `Hello Mr ${options.surname}`
* next()
* middleware (config) {
* return async (ctx, next) => {
* ctx.response.body = `Hello Mr ${config.surname}`
* await next()
* }

@@ -25,2 +25,7 @@ * }

/**
* @external OptionDefinition
* @see https://github.com/75lb/command-line-args/blob/master/doc/option-definition.md
*/
/**
* @alias module:middleware-plugin

@@ -35,4 +40,4 @@ */

/**
* Return one or more options definitions to collect command-line input.
* @returns {OptionDefinition|OptionDefinition[]}
* Return one or more [OptionDefinition](https://github.com/75lb/command-line-args/blob/master/doc/option-definition.md) objects to collect command-line input.
* @returns {external:OptionDefinition|external:OptionDefinition[]}
*/

@@ -42,5 +47,5 @@ optionDefinitions () {}

/**
* Return one of more Koa middleware functions. Optionally, emit `verbose` events to `ctx.app`.
* @param {object} - The active config object.
* @param {Lws} - The active `lws` instance.
* Return one of more [Koa middleware functions](https://github.com/koajs/koa/blob/master/docs/guide.md).
* @param {object} - The active `lws` config object.
* @param {Lws} - The active `lws` instance. Typically, only required for access to `lws.server`.
* @returns {function|function[]}

@@ -47,0 +52,0 @@ */

@@ -43,7 +43,12 @@ const flatten = require('reduce-flatten')

const MiddlewareClasses = modules.map((moduleItem, index) => {
/* load module */
if (typeof moduleItem === 'string') {
const loadModule = require('load-module')
return loadModule(moduleItem.toLowerCase(), options)
moduleItem = loadModule(moduleItem.toLowerCase(), options)
}
/* validate module */
if (typeof moduleItem === 'function' && moduleItem.prototype.middleware) {
return moduleItem
} else {
return moduleItem
throw new Error('Invalid middleware: please supply a class with a `middleware` method.')
}

@@ -50,0 +55,0 @@ })

{
"name": "lws",
"author": "Lloyd Brookes <75pound@gmail.com>",
"version": "2.0.1",
"version": "2.0.2",
"description": "A lean, modular web server for rapid full-stack development",

@@ -38,3 +38,3 @@ "repository": "https://github.com/lwsjs/lws.git",

"command-line-args": "^5.1.1",
"command-line-usage": "^5.0.5",
"command-line-usage": "^6.0.0-1",
"create-mixin": "^2.0.1",

@@ -47,3 +47,3 @@ "koa": "^2.7.0",

"reduce-flatten": "^2.0.0",
"typical": "^5.0.0",
"typical": "^5.1.0",
"walk-back": "^3.0.1"

@@ -50,0 +50,0 @@ },

@@ -37,2 +37,4 @@ [![view on npm](https://img.shields.io/npm/v/lws.svg)](https://www.npmjs.org/package/lws)

Now your server is running, the next step is to attach some middleware to process requests.
### Using middleware plugins

@@ -69,4 +71,5 @@

middleware () {
return function (ctx) {
return async (ctx, next) => {
ctx.body = 'Hello from lws!'
await next()
}

@@ -89,2 +92,8 @@ }

## Install
```
$ npm install --save-dev lws
```
## Documentation

@@ -91,0 +100,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc