Skip to content
This repository has been archived by the owner on Nov 17, 2022. It is now read-only.

docs: mock use middleware #612

Merged
merged 3 commits into from
Oct 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions website/docs/guide/basic/mock.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,22 @@ export default {
```

完整的语法请参考 [Mock.js 文档](http://mockjs.com/examples.html)。

## 处理请求数据

如果用户希望使用一些中间件来处理请求的数据(`req` 对象),可以参考以下的示例代码:

```ts
import bodyParser from 'body-parser';
import type { Request, Response } from 'express';

export default {
'POST /api/login': (req: Request, res: Response) => {
bodyParser.json({ limit: '5mb', strict: false })(req, res, () => {
console.log(req.body);

res.send({});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释解释一下, 这个 req 和 res 的定义可以从哪里看到定义(外链也可)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

增加了类型

})
},
}
```