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

koa源码分析(二) - context.js #6

Open
brunoyang opened this issue Oct 8, 2015 · 0 comments
Open

koa源码分析(二) - context.js #6

brunoyang opened this issue Oct 8, 2015 · 0 comments

Comments

@brunoyang
Copy link
Owner

本文分为四个部分,分别对应源码的四个文件。

依赖

  • createError: 将小于500的错误往前端报,大于500的内部消化
  • delegate:将某个对象的方法代理至某个对象上

源码分析

context暴露了一个对象,包含了多个方法,并将request和response的方法代理到自己身上。

onerror

this.app继承自event.emitter,通过error事件触发onerror。onerror方法将取得的error code设置为传入err的status,默认为500,在设置完http相应的长度、状态码及body后,发送该响应至用户。

request和response

143~191行,通过delegate方法将response的request的方法绑定至context上。

@brunoyang brunoyang changed the title koa源码分析(二) koa源码分析(二) - context.js Oct 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant