From 9a797d1c6a1742086834d2bc07024d143bf326c7 Mon Sep 17 00:00:00 2001 From: luhc228 Date: Thu, 20 Oct 2022 17:51:32 +0800 Subject: [PATCH 1/3] docs: mock use middleware --- website/docs/guide/basic/mock.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/website/docs/guide/basic/mock.md b/website/docs/guide/basic/mock.md index 79a5b96c3..c2bce88e0 100644 --- a/website/docs/guide/basic/mock.md +++ b/website/docs/guide/basic/mock.md @@ -132,3 +132,21 @@ export default { ``` 完整的语法请参考 [Mock.js 文档](http://mockjs.com/examples.html)。 + +## 处理请求数据 + +如果用户希望使用一些的中间件来处理请求的数据(`req` 对象),可以参考以下的示例代码: + +```ts +import bodyParser from 'body-parser'; + +export default { + 'POST /api/login': (req, res) => { + bodyParser.json({ limit: '5mb', strict: false })(req, res, async () => { + console.log(req.body); + + res.send({}); + }) + }, +} +``` From 16bed9a659df893b827e65b6cf0d58880775f38b Mon Sep 17 00:00:00 2001 From: luhc228 Date: Fri, 21 Oct 2022 11:35:06 +0800 Subject: [PATCH 2/3] fix: comment --- website/docs/guide/basic/mock.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/website/docs/guide/basic/mock.md b/website/docs/guide/basic/mock.md index c2bce88e0..1da8dfe6a 100644 --- a/website/docs/guide/basic/mock.md +++ b/website/docs/guide/basic/mock.md @@ -135,14 +135,15 @@ export default { ## 处理请求数据 -如果用户希望使用一些的中间件来处理请求的数据(`req` 对象),可以参考以下的示例代码: +如果用户希望使用一些中间件来处理请求的数据(`req` 对象),可以参考以下的示例代码: ```ts import bodyParser from 'body-parser'; +import { Request, Response } from 'express'; export default { - 'POST /api/login': (req, res) => { - bodyParser.json({ limit: '5mb', strict: false })(req, res, async () => { + 'POST /api/login': (req: Request, res: Response) => { + bodyParser.json({ limit: '5mb', strict: false })(req, res, () => { console.log(req.body); res.send({}); From cad2a981a1792dc0229ea0d9a43765e7617cad07 Mon Sep 17 00:00:00 2001 From: luhc228 Date: Thu, 27 Oct 2022 10:37:41 +0800 Subject: [PATCH 3/3] docs: add types --- website/docs/guide/basic/mock.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/guide/basic/mock.md b/website/docs/guide/basic/mock.md index 1da8dfe6a..d065e6927 100644 --- a/website/docs/guide/basic/mock.md +++ b/website/docs/guide/basic/mock.md @@ -139,7 +139,7 @@ export default { ```ts import bodyParser from 'body-parser'; -import { Request, Response } from 'express'; +import type { Request, Response } from 'express'; export default { 'POST /api/login': (req: Request, res: Response) => {