3 category: JavaScript libraries
10 Koa is a web framework for Node.js.
12 - <https://koajs.com/>
17 app.use(function * (next) {
25 ctx.state.user = yield User.find(id).fetch()
27 ctx.cookies.set('foo', 'hello', { signed: true })
28 ctx.cookies.get('foo')
36 ctx.header // ctx.headers
40 ctx.origin // => 'http://example.com'
41 ctx.href // => 'http://example.com/foo?q=hello'
43 ctx.query // { q: 'hello' }
46 ctx.querystring // and =
57 ctx.is() // .is('html') .is('text/html')
58 ctx.accepts() // .accepts('html') .accepts('html', 'json')
59 ctx.acceptsEncodings() // .acceptsEncodings('gzip')
61 ctx.acceptsLanguages()
64 ctx.request.type // => 'image/jpg'
65 ctx.request.charset // => 'utf-8'
66 ctx.request.protocol // => 'https'
67 ctx.request.secure // => true
68 ctx.request.ip // (supports X-Forwarded-For if app.proxy)
70 ctx.request.subdomains
82 ctx.throw('name required', 403)
83 ctx.throw(403, 'name required')
85 ctx.assert(ctx.state.user, 401, 'You must log in')
91 exports.conditionalGet = require('koa-conditional-get');
92 exports.responseTime = require('koa-response-time');
93 exports.ratelimit = require('koa-ratelimit');
94 exports.compress = require('koa-compress');
95 exports.rewrite = require('koa-rewrite');
96 exports.favicon = require('koa-favicon');
97 exports.session = require('koa-session');
98 exports.static = require('koa-static');
99 exports.logger = require('koa-logger');
100 exports.mount = require('koa-mount');
101 exports.etag = require('koa-etag');