Skip to content

Commit

Permalink
docs: document for middleware order (#724)
Browse files Browse the repository at this point in the history
Closes #723
  • Loading branch information
popomore committed Apr 14, 2017
1 parent d6be949 commit 1ab42e0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/source/zh-cn/basics/middleware.md
Expand Up @@ -84,6 +84,26 @@ module.exports = {
};
```

我们还可以动态修改现有中间件的顺序,中间件的加载顺序和插件顺序不同,是由 `app.config.coreMiddleware``app.config.appMiddleware` 这两个数组合并而成的。

```js
// app.js
module.exports = app => {
// 在中间件最前面统计请求时间
app.config.coreMiddleware.unshift('report');
};

// app/middleware/report.js
module.exports = () => {
return function* (next) {
const startTime = Date.now();
yield next;
// 上报请求时间
reportTime(Date.now() - startTime);
}
};
```

**配置项以及区分各运行环境的配置,请查看[配置](./config.md)章节。**

## 框架默认中间件
Expand Down

0 comments on commit 1ab42e0

Please sign in to comment.