We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
#22 の一部
Connectの仕組みについてまとめる。
思想的にはRackから来てて、RackのものはPythonのWSGIミドルウェアから影響受けてそう。
おおまかな仕組みとしては
.use(middlware)
というだけ。 エラーハンドリングはmiddlewareの引数の数で分けている。
後はルーティングの仕組みもあるけど、middlewareとは別に関係ないのでこの書籍は省略する。
この仕組みはHTTPサーバのミドルウェアスタックの話と深い関係がありそうなので、 あんまり深追いはしないでHTTPサーバではよくある仕組みだよみたいな話に留める。
koaの場合はgeneratorを使うので少しnextの扱い方が異なっている。 Connectの場合はnextは終了の的な意味合いだけど、 yeild nextと書けば、そのmiddlewareは前後の処理も書くことができる。
next
エラーハンドリングはそれを上手く使ってる。
try { yield next; } catch (err) { this.status = err.status || 500; this.body = err.message; this.app.emit('error', err, this); }
The text was updated successfully, but these errors were encountered:
use
Connectの仕組み
089c2af
close #57
Successfully merging a pull request may close this issue.
#22 の一部
Connectの仕組みについてまとめる。
思想的にはRackから来てて、RackのものはPythonのWSGIミドルウェアから影響受けてそう。
おおまかな仕組みとしては
.use(middlware)
はmiddlewareをstackに追加するというだけ。
エラーハンドリングはmiddlewareの引数の数で分けている。
後はルーティングの仕組みもあるけど、middlewareとは別に関係ないのでこの書籍は省略する。
内容
この仕組みはHTTPサーバのミドルウェアスタックの話と深い関係がありそうなので、
あんまり深追いはしないでHTTPサーバではよくある仕組みだよみたいな話に留める。
koaの場合はgeneratorを使うので少し
next
の扱い方が異なっている。Connectの場合はnextは終了の的な意味合いだけど、 yeild nextと書けば、そのmiddlewareは前後の処理も書くことができる。
エラーハンドリングはそれを上手く使ってる。
The text was updated successfully, but these errors were encountered: