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
- Lws ⏏
- new Lws(config)
- instance
- .server :
Server
- .stack :
MiddlewareStack
- .config :
LwsConfig
- .createServer() ⇒
Server
- .useMiddlewareStack()
- .useView()
- "verbose" (key, value)
- .server :
- static
- .create(config) ⇒
Lws
- .create(config) ⇒
- Lws ⏏
Kind: Exported class
Emits: event:verbose
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. |
The output of Node's standard http, https or http2 .createServer()
method. Created and set by lws.createServer()
.
Kind: instance property of Lws
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
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
Attach the Middleware stack to the server. Must be run after lws.createServer()
.
Kind: instance method of Lws
Attach the view specified in the config.
Kind: instance method of Lws
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' } . |
Launch a listening HTTP, HTTPS or HTTP2 server configured as specified by the supplied config.
Kind: static method of Lws
Param | Type |
---|---|
config | LwsConfig |