master
TJ Holowaychuk 2013-09-02 19:13:47 -07:00
parent c6dc504ce8
commit 4a0c55cc96
1 changed files with 14 additions and 0 deletions

View File

@ -39,6 +39,20 @@ app.use(function(next){
![koa middleware](https://i.cloudup.com/N7L5UakJo0.gif)
1. Create a date to track duration
2. Yield control to the next middleware
3. Create another date to track response time
4. Yield control to the next middleware
5. Yield immediately since `contentLength` only works with responses
6. Yield upstream to Koa's noop middleware
7. Ignore setting the body unless the path is "/"
8. Set the response to "Hello World"
9. Ignore setting Content-Length when no body is present
10. Set the field
11. Output log line
12. Set `X-Response-Time` header field before response
13. Hand off to Koa to handle the response
Next we'll look at the best practices for creating Koa middleware.
## Middleware Best Practices