koa-plus is the koa framework (v2) extended for APIs. Optimized for security, scalability, and productivity.
X-Request-Id
headers as X-Client-Request-Id
304 Not Modified
)ctx.debug
(or ctx.app.debug
) logging via the debug modulectx.config
(or, app.context.config)Each feature can be disabled individually.
Install koa-plus
via yarn or npm:
npm install koa-plus --save
Simply replace your existing koa
require with koa-plus
Old:
const Koa = require('koa') const app = new Koa() // ...
New:
const Koa = require('koa-plus') const app = new Koa() // ...
Some of the middleware included in koa-plus
allows for options. To pass options to these middleware, simply pass the options to the constructor.
body
: Use the same options as the koa-body
middleware accepts. Docscompress
: Use the same options as the koa-compress
middleware accepts. Docscors
: Use the same options as the kcors
middleware accepts. Docsdebug
: Set the name
of the debug loggerhelmet
: Use the same options as the helmet
middleware accepts. Docsjson
: Use the same options as the koa-json
middleware accepts. Docslogger
: Use format
for the logger format, and the remaining options as what morgan
accepts Docsconst Koa = require('koa-plus') const app = new Koa({ body: { jsonLimit: '10kb' // Sets the json request body limit to 10k }, compress: { threshold: 2048 // Sets the threshold to Gzip responses at 2k (2048 bytes) }, cors: { origin: '*' // Set the `Access-Control-Allow-Origin` header to be `*` }, debug: { name: 'worker' // Set the debug logger name }, helmet: { noCache: true, // Sets the `Cache-Control` headers to prevent caching frameguard: { action: 'deny' // Set the `X-Frame-Options' header to be `DENY` } }, json: { pretty: false // Disables pretty-printing }, logger: { format: 'dev' // Use the `dev` format of logging } })
Each of the middleware in koa-plus can be disabled individually by using the enabled
option.
As an example, to reset koa-plus
back to basic koa
functionality, use the following config:
const Koa = require('koa-plus') const app = new Koa({ body: { enabled: false }, compress: { enabled: false }, cors: { enabled: false }, debug: { enabled: false }, etag: { enabled: false }, helmet: { enabled: false }, json: { enabled: false }, logger: { enabled: false }, requestId: { enabled: false }, responseTime: { enabled: false } })
To run the tests locally, simply run
or
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4