Skip to content

Files

Latest commit

 

History

History
122 lines (88 loc) · 4.37 KB

lws.md

File metadata and controls

122 lines (88 loc) · 4.37 KB

lws

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.

Example

// Middleware to handle requests
class Greeter {
  middleware () {
    return async (ctx, next) => {
      ctx.response.body = 'Hello!'
      await next()
    }
  }
}

// Launch a HTTP server with the Greeter middleware attached
const lws = await Lws.create({ stack: Greeter })

// $ curl http://127.0.0.1:8000
// Hello!

// shutdown
lws.server.close()

Lws ⏏

Kind: Exported class
Emits: event:verbose

new Lws(config)

Contructs an empty Lws instance but does not initialise it. Use the Lws.create(config) factory method to create, initialise and launch a lws server.

Param Type Description
config LwsConfig Server config.

lws.server : Server

The output of Node's standard http, https or http2 .createServer() method. Created and set by lws.createServer().

Kind: instance property of Lws

lws.stack : MiddlewareStack

The middleware plugin stack as defined by the config. Created and set by lws.useMiddlewareStack().

Kind: instance property of Lws

lws.config : LwsConfig

The active lws config.

Kind: instance property of Lws

lws.createServer() ⇒ Server

Create a HTTP, HTTPS or HTTP2 server, depending on config. Returns the output of Node's standard http, https or http2 .createServer() method also assigning it to lws.server.

Kind: instance method of Lws

lws.useMiddlewareStack()

Attach the Middleware stack to the server. Must be run after lws.createServer().

Kind: instance method of Lws

lws.useView()

Attach the view specified in the config.

Kind: instance method of Lws

"verbose" (key, value)

An event stream of debug information.

Kind: event emitted by Lws

Param Type Description
key string An identifying string, e.g. server.socket.data.
value * The value, e.g. { socketId: 1, bytesRead: '3 Kb' }.

Lws.create(config) ⇒ Lws

Launch a listening HTTP, HTTPS or HTTP2 server configured as specified by the supplied config.

Kind: static method of Lws

Param Type
config LwsConfig