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

在监听request的回调中拿不到ctx.request.body #3404

Closed
menkeydyvh opened this issue Jan 14, 2019 · 8 comments
Closed

在监听request的回调中拿不到ctx.request.body #3404

menkeydyvh opened this issue Jan 14, 2019 · 8 comments

Comments

@menkeydyvh
Copy link

在使用

app.on('request', ctx => {
//拿不到下面这个的值
ctx.request.body
});

相关环境信息

  • 操作系统:windows
  • Node 版本:v8.9.3
  • Egg 版本: 2.11.0
@popomore
Copy link
Member

是的,这个是请求才进入,还未开始处理,可以自己写个中间件拦截。

@atian25
Copy link
Member

atian25 commented Jan 15, 2019

还是说下你的原始诉求吧

@egg-bot
Copy link

egg-bot commented Jan 15, 2019

Hello @menkeydyvh. Please provide a reproducible example following the instruction.

Issues labeled by Need Reproduce will be closed if no activities in 7 days.


@menkeydyvh,请根据这个说明提供最小可复现代码。

如果在 7 天内没有进展会被自动关闭。

@menkeydyvh
Copy link
Author

@popomore 有没有 request after 可以监听到ctx.request.body 或者ctx.request.rowbody有数据的时候?

@menkeydyvh
Copy link
Author

@atian25 做一个请求日志记录 看到别人是用这样监听的 但是监听的ctx.request.body 是还没被解析出来的

@atian25
Copy link
Member

atian25 commented Jan 15, 2019

你看的是 Express 的吧, Koa 不需要这样,可以了解下洋葱模型。

直接写个 Middleware 分别在 await next() 两端记录即可

@menkeydyvh
Copy link
Author

@atian25 嗯 我后续也改成这样了 如果在这个事件框架还没解析这个那我只能去中间件处理了

@atian25
Copy link
Member

atian25 commented Jan 15, 2019

在 Koa 里面,尽可能少用这些事件。中间件很简单的,几句话搞定。

@atian25 atian25 closed this as completed Jan 15, 2019
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

4 participants