Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mock的自定义函数中的req获取不到body #86

Closed
dicklwm opened this issue Jan 16, 2017 · 21 comments
Closed

mock的自定义函数中的req获取不到body #86

dicklwm opened this issue Jan 16, 2017 · 21 comments

Comments

@dicklwm
Copy link

dicklwm commented Jan 16, 2017

.roadhogrc.mock.js的配置:

'POST /api/login': (req, res)=> {
    //  undefined   {}   {}
    console.log(req.body,req.params,req.query);
    res.end('ok');
}

server/app.js中的login方法:

export async function login (params) {
  return request('/api/login', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({userName:"minlee",password:"2"})
  })
}
  • 我用REST Client去POST访问接口也是这样
    image

  • 结果在req中获取到的req.body是undefined,是我配置有问题还是咋的?

  • 我把mock改成GET接口也是获取不到body

@sorrycc
Copy link
Owner

sorrycc commented Jan 16, 2017

我忘记加相关的中间件了,比如 busboy

@dicklwm
Copy link
Author

dicklwm commented Jan 16, 2017

好的,下个版本什么时候可以更新啊?

@sorrycc sorrycc added this to the 0.6 milestone Jan 16, 2017
@DickyT
Copy link

DickyT commented Jan 30, 2017

谢谢!!!

@showonne
Copy link

Mark, 期待更新。

@yvanwangl
Copy link

@sorrycc 我安装了~0.6.0-beta1版还是获取不到body的数据呢?不是已经修复了嘛

@pkaq
Copy link

pkaq commented Mar 21, 2017

用了最新版本同样获取不到 加了body-parser也没用

@zuiidea
Copy link

zuiidea commented Apr 1, 2017

修复了吗?

@sorrycc
Copy link
Owner

sorrycc commented Apr 2, 2017

修复了,但还没发。

@sorrycc
Copy link
Owner

sorrycc commented Apr 10, 2017

Try roadhog@0.6.0-beta.3

@sorrycc sorrycc reopened this Apr 10, 2017
@sorrycc sorrycc closed this as completed Apr 10, 2017
@sapronlee
Copy link

0.6.0-beta.3 中mock下req.body依旧拿不到,看了看代码,发现里面的确是依赖了body-parser,但是runServer里面没有使用啊

@zuiidea
Copy link

zuiidea commented Apr 11, 2017

@sapronlee
npm uninstall roadhog -g
npm install roadhog@0.6.0-beta.3 -g

@sapronlee
Copy link

@zuiidea OK,谢谢,已经OK

@OptimusYang
Copy link

@zuiidea 执行后 还是拿不到,一样的报错。

@zuiidea
Copy link

zuiidea commented Apr 13, 2017

@OptimusYang roadhog -v应该不是0.6.0-beta.3

  • C:\Users\{你的电脑名字}\AppData\Roaming\npm下删除roadhog.cmd和roadhog,及C:\Users\{你的电脑名字}\AppData\Roaming\npm\node_modules\roadhog
  • npm install roadhog@0.6.0-beta.3 -g

@OptimusYang
Copy link

@zuiidea version是0.6.0-beta.3, 同时我也执行了删除和重新安装,还是拿不到,代码版本就是4.1的branch。 挺郁闷的。

@zuiidea
Copy link

zuiidea commented Apr 14, 2017

@OptimusYang 你把packge.json里的roadhog去掉,再npm install一下呢

@OptimusYang
Copy link

@zuiidea 更新了你最新的trunk流代码,就是你merge完之后的,是可以了,然后我打开旧的4.1的代码,移除了roadhog的依赖,手动安装roadhogbeta3,也可以了。 这是为什么呢?我看到你在最新的版本里也去掉了roadhog的依赖转为自己手动安装。

@OptimusYang
Copy link

@zuiidea 发现写在依赖里,重新安装后,拿到的是beta2版本,这是怎么回事?

@zuiidea
Copy link

zuiidea commented Apr 14, 2017

@OptimusYang我也发现了,所以才让你删了装的,也许是cnpm的原因吧

@scottyan19
Copy link

被这个问题折腾了一天, 还以为是我写错了...

@tun100
Copy link

tun100 commented Apr 20, 2018

关注关注!现在还是不行

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests