1.6.1 • Published 8 years ago
kmid v1.6.1
kmid
koa2 中间件集
access(options) 请求记录
options配置warnTimenumber 请求时间超过 该数值 显示警告。 单位 msfiltersarray 过滤 path 不显示请求记录
app.use(kmid.access());queryfix() 处理微信商城 url 后被加上?10000skip=true时导致query参数解析错乱的问题
app.use(kmid.queryfix());parse(opts) body 数据解析中间件
cobodySee co-body for a full list of optionslimitnumber or string representing the request size limit (10mb)strictwhen set to true, JSON parser will only accept arrays and objects; when false will accept anything JSON.parse accepts. Defaults to true. (also strict mode will always return object).queryStringan object of options when parsing query strings and form data. See qs for more information.jsonTypesis used to determine what media type co-body will parse as json, this option is passed directly to the type-is library.formTypesis used to determine what media type co-body will parse as form, this option is passed directly to the type-is library.textTypesis used to determine what media type co-body will parse as text, this option is passed directly to the type-is library.
formidableSee node-formidable for a full list of optionsbytesExpected--{Integer}-- The expected number of bytes in this form, defaultnullmaxFields--{Integer}-- Limits the number of fields that the querystring parser will decode, default1000maxFieldsSize--{Integer}-- Limits the amount of memory all fields together (except files) can allocate in bytes. If this value is exceeded, an 'error' event is emitted, default2mb (2 - 2 - 1024)uploadDir--{String}-- Sets the directory for placing file uploads in, defaultos.tmpDir()keepExtensions--{Boolean}-- Files written touploadDirwill include the extensions of the original files, defaultfalsehash--{String}-- If you want checksums calculated for incoming files, set this to either'sha1'or'md5', defaultfalsemultiples--{Boolean}-- Multiple file uploads or no, defaulttrueonFileBegin--{Function}-- Special callback on file begin. The function is executed directly by formidable. It can be used to rename files before saving them to disk. See the docs
onerror
app.use(kmid.parse());proxy(prefix, opts) 请求转发中间件 依赖http-proxy
prefix匹配前缀下的所有请求都会转发opts配置 更多参数请见http-proxyrewrite重写 url 函数target转发 urlwarnTime显示警告 时间阀
// middleware
app.use(
kmid.proxy('/services', {
target: 'https://api.github.com/users',
changeOrigin: true,
rewrite: path => path.replace(/^\/services(\/|\/\w+)?$/, ''),
warnTime: 10 * 1000
})
);static(root, opts) 静态文件 依赖koa-send
root根目录. nothing above this root directory can be servedopts配置defer是否滞后处理 (defaults tofalse)maxage浏览器缓存 max-age 毫秒. (defaults to0)hidden是否响应隐藏文件 (defaults tofalse)gzip开启 gzip (defaults totrue)formatIf notfalse(defaults totrue), format the path to serve static file servers and not require a trailing slash for directories, so that you can do both/directoryand/directory/setHeadersFunction to set custom headers on response.extensions匹配后缀 数组 (defaults tofalse)
app.use(kmid.static(path.join(__dirname, '..', 'static'), opts));views(root, opts) 视图中间件 依赖nunjucks 模板
root: 指定存放模板的目录 (默认 './views')opts: nunjucks 模板引擎的设置 nunjucks 文档ext: (默认值html) 模板文件后缀filters: 过滤器 {name:func},{name:func}globals: 全局变量 {name:value},{name:value}autoescape(默认值: true) 控制输出是否被转义,查看 AutoescapingthrowOnUndefined(默认值: false) 当输出为 null 或 undefined 会抛出异常trimBlocks(默认值: false) 自动去除 block/tag 后面的换行符lstripBlocks(默认值: false) 自动去除 block/tag 签名的空格watch(默认值: false) 当模板变化时重新加载。使用前请确保已安装可选依赖 chokidar。noCache(默认值: false) 不使用缓存,每次都重新编译tags(默认值: see nunjucks syntax) 定义模板语法,查看 Customizing Syntax
app.use(kmid.views(path.join(__dirname, '..', 'views'), opts));
///
await ctx.render('user.html')
// 或者
await ctx.render('user')
// 或者
yield ctx.render('user')session(opts) session 中间件 依赖ioredis
keycookie 存储的标识storeredis 配置 更多配置见ioredisexpiresession 过期时间 millisecondsportRedis porthostRedis hostpasswordredis password,dbredis db
cookiecookies.set optionsmaxAgea number representing the milliseconds from Date.now() for expiryexpiresa Date object indicating the cookie's expiration date (expires at the end of session by default).patha string indicating the path of the cookie (/ by default).domaina string indicating the domain of the cookie (no default).securea boolean indicating whether the cookie is only to be sent over HTTPS (false by default for HTTP, true by default for HTTPS). Read more about this option below.httpOnlya boolean indicating whether the cookie is only to be sent over HTTP(S), and not made available to client JavaScript (true by default).sameSitea boolean or string indicating whether the cookie is a "same site" cookie (false by default). This can be set to 'strict', 'lax', or true (which maps to 'strict').signeda boolean indicating whether the cookie is to be signed (false by default). If this is true, another cookie of the same name with the .sig suffix appended will also be sent, with a 27-byte url-safe base64 SHA1 value representing the hash of cookie-name=cookie-value against the first Keygrip key. This signature key is used to detect tampering the next time a cookie is received.overwritea boolean indicating whether to overwrite previously set cookies of the same name (false by default). If this is true, all cookies set during the same request with the same name (regardless of path or domain) are filtered out of the Set-Cookie header when setting this cookie.
app.use(kmid.session({
store: {
expire: 86400000*7
port: config.redis.port,
host: config.redis.host,
password: config.redis.password,
db: config.redis.sessionDB
},
maxAge: 86400000*7,
key: 'web_wx',
}));
//
ctx.session.username = 'jaskang'
//
const user = ctx.session.username;中间件来源
koa-bodyhttps://github.com/dlau/koa-body/tree/koa2koa-statichttps://github.com/koajs/statickoa-viewhttps://github.com/d-band/koa-viewkoa-proxieshttps://github.com/vagusX/koa-proxies
1.6.1
8 years ago
1.6.0
8 years ago
1.5.4
8 years ago
1.5.3
8 years ago
1.5.2
8 years ago
1.5.1
8 years ago
1.5.0
8 years ago
1.4.0
8 years ago
1.3.0
8 years ago
1.2.9
8 years ago
1.2.8
8 years ago
1.2.7
8 years ago
1.2.6
8 years ago
1.2.5
8 years ago
1.2.4
8 years ago
1.2.3
8 years ago
1.2.2
8 years ago
1.2.1
8 years ago
1.2.0
8 years ago
1.1.6
9 years ago
1.1.5
9 years ago
1.1.4
9 years ago
1.1.3
9 years ago
1.1.2
9 years ago
1.1.1
9 years ago
1.0.9
9 years ago
1.0.8
9 years ago
1.0.7
9 years ago
1.0.6
9 years ago
1.0.5
9 years ago
1.0.4
9 years ago
1.0.3
9 years ago
1.0.2
9 years ago
1.0.1
9 years ago