File tree 1 file changed +18
-0
lines changed
1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,20 @@ Connectでは`app.stack`にまだに_middleware_が保持されています。
84
84
` next() ` がないということは` hello.js ` がこの連続する_middleware_の最後となっていることがわかります。
85
85
仮に、これより先に_middleware_が登録されていたとしても無視されます。
86
86
87
+ つまり、処理的には以下のようにstackを先頭から一個づつ取り出して、処理していくという方法が取られています。
88
+
89
+ ``` js
90
+ let req = " ..." ,
91
+ res = " ..." ;
92
+ function next (){
93
+ let middleware = app .stack .shift ();
94
+ // nextが呼ばれれば次のmiddleware
95
+ middleware (req, res, next);
96
+ }
97
+ next ();// 初回
98
+ ```
99
+
100
+
87
101
このような_middleware_を繋げた形を_middleware stack_と呼ぶことがあります。
88
102
89
103
HTTPサーバではこのような_middleware stack_を作って使うものは既にあり、
@@ -94,3 +108,7 @@ Rackを参考にして実装されています。
94
108
95
109
- [ Ruby - Rack解説 - Rackの構造とRack DSL - Qiita] ( http://qiita.com/higuma/items/838f4f58bc4a0645950a#2-5 " Ruby - Rack解説 - Rackの構造とRack DSL - Qiita ")
96
110
111
+ 次に、この_middleware stack_をどう処理しているのかを、
112
+ 具体的な実装を書きながら見て行きましょう。
113
+
114
+ ## 実装してみよう
You can’t perform that action at this time.
0 commit comments