-
Notifications
You must be signed in to change notification settings - Fork 87
Using middleware
Lloyd Brookes edited this page Jul 8, 2017
·
13 revisions
Each incoming request passes through your server's middleware stack. You may specify your own personal stack (via --stack
) or work with the built-in default.
Name | Description |
---|---|
↓ Body Parser | Parses the request body, making ctx.request.body available to downstream middleware. |
↓ Request Monitor | Feeds traffic information to the --verbose output. |
↓ Log | Outputs an access log or stats view to the console. |
↓ Cors | Support for adding Cross-Origin Resource Sharing (CORS) headers |
↓ Json | Pretty-prints JSON responses. |
↓ Rewrite | URL Rewriting. Use to re-route requests to local or remote destinations. |
↓ Blacklist | Forbid access to sensitive or private resources |
↓ Conditional Get | Support for HTTP Conditional requests. |
↓ Mime | Customise the mime-type returned with any static resource. |
↓ Compress | Compress responses using gzip. |
↓ Mock Response | Mock a response for any given request. |
↓ SPA | Support for Single Page Applications. |
↓ Static | Serves static files. |
↓ Index | Serves directory listings. |
Local-web-server uses Koa for its middleware stack. See here for a guide explaining how Koa middleware works and why stack order is significant. See here for the ctx
object documentation.
View built-in middleware list
$ ws middleware-list
[ 'lws-body-parser',
'lws-request-monitor',
'lws-log',
'lws-cors',
'lws-json',
'lws-rewrite',
'lws-blacklist',
'lws-conditional-get',
'lws-mime',
'lws-compress',
'lws-mock-response',
'lws-spa',
'lws-static',
'lws-index' ]