摘要: # 文章 ## middleware 中间件 > 正是因为中间件的扩展性才使得 `Koa` 的代码简单灵活。 在 `app.js` 中,有这样一段代码: ```js app.use(async (ctx, next)=>{ await next() ctx.response.type = 'text/html' ctx.response.body = 'Hello World' }) ``` 它的作用是:每收到一个 `http` 请求,`Koa` 都会调用通过 `app.use()` 注册的 `async` 函数,同时为该函数传入 `ctx` 和 `next` 两个参数。而这个 `async` 函数就是我们所说的中间件。 阅读全文
posted @ 2017-12-22 11:17 iKcamp 阅读(472) 评论(0) 推荐(0) 编辑