koa-compress
Compress middleware for Koa
Example
1 | const compress = require('koa-compress') |
Options
The options are passed to zlib
filter: An optional function that checks the response content type to decide whether to compress. By default, it uses compressible
threshold: Minimum response size in bytes to compress. Default 1024 byte or 1kb.
koa-morgan
HTTP Request logger middleware for node.js
1 | const morgan = require('morgan') |
morgan(format, options)
Create a new morgan logger middleware function using the given format
and options
.
The format
argument amay be a string of a predefined name, a string fo a format string, or a function that will produce a log entry.
The format
function will be called with three arguments tokens
, req
and res
, where tokens
is object with all tokens, req
is the HTTP request and res
is the HTTP response. The function is expected to return a string that will be the log line, or undefined
/null
to skip logging.
predefined format string
combined
: Standard Apache combined log output
1 | :remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent" |
common
: Standard Apache common log output
dev
short
tiny
1 | :method :url :status :res[content-length] - :response-time ms |
write logs to a file
Single file
Simple app that will log all request in the Apache combined format to the file access.log
1 | const fs = require('fs') |
koa-session
Simple session middleware for koa. Default is cookie-based session and support external store.
Require Node 7.6 or greater for asycn/await support
1 | const session = require('koa-session') |
Options
The cookie name is controlled by the key option, which default to ‘koa:sess’. All other options are passed to ctx.cookies.get()
and ctx.cookies.set()
allowing you to control security, domain, path and signing among other setting.