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

the function named before of resource will not be execute #31

Closed
suiandtang opened this issue Jun 29, 2015 · 5 comments
Closed

the function named before of resource will not be execute #31

suiandtang opened this issue Jun 29, 2015 · 5 comments
Labels

Comments

@suiandtang
Copy link

我要在post方法执行前后记录日志信息,按照api文档中关于before,after的用法,发现before方法没有被执行,请问如何实现。

@zackyang000
Copy link
Owner

是的, 这是我之前挖的一个坑 T_T

做的时候就知道可能有 bug, 不过当时由于没有使用 before 这个 api, 所以就没有去测试它.

0.7 版中将解决这个问题. (预计本周完成) 目前请暂时使用 after.

另外, 设计 before 主要是为了进行一些验证, 如果不符合规则等, 在最后 return false 将阻止相应的操作执行. after 主要是为了可能在插入数据之后还有一些后续操作. 比如要重新计算其他 resource 的某个字段, 或可能要做一些 log. 因为 before 会阻塞整个请求, 所以建议如果只是记录 log 的话在 after 中进行, 因为它是异步的, 当 REST 的操作完成后将直接返回给客户端, 剩下的操作将在返回后执行.

这一点没有在文档中进行说明, 表示抱歉. 之后我会添加到文档中.

感谢关注.

@zackyang000 zackyang000 changed the title bug the function named before of resource will not be execute Jun 29, 2015
@zackyang000
Copy link
Owner

Fixed it on 969ab5d.

@suiandtang
Copy link
Author

我的实际意图是要记录 每次操作的服务器处理耗时。
设计在before中放入开始时间,在after中用(当前时间-开始时间)计算出方法的总耗时,是否可行?
或者有其他更好的记录方式吗

@zackyang000
Copy link
Owner

可以考虑使用 response-time 中间件.

@suiandtang
Copy link
Author

谢谢,已经搞定

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

No branches or pull requests

2 participants