copy tweaks (#731)

master
Zack Tanner 2016-05-12 23:27:18 -07:00 committed by Yiyu He
parent 41afac3eba
commit 808768a597
2 changed files with 5 additions and 5 deletions

View File

@ -41,19 +41,19 @@ app.listen(3000);
## Middleware
Koa is an middleware framework, it can take 3 different kind function as middleware:
Koa is a middleware framework that can take 3 different kinds of functions as middleware:
* common function
* async function
* generatorFunction
Here we write an logger middleware with different function.
Here is an example of logger middleware with each of the different functions:
### Common function
```js
// Middleware normally take two parameters (ctx, next), ctx is the context for one request,
// next is an function that is invoked to execute the downstream middleware. It returns a Promise with a then function for running code after completion.
// Middleware normally takes two parameters (ctx, next), ctx is the context for one request,
// next is a function that is invoked to execute the downstream middleware. It returns a Promise with a then function for running code after completion.
app.use((ctx, next) => {
const start = new Date();

View File

@ -1,7 +1,7 @@
# Guide
This guide covers Koa topics that are not directly API related, such as best practices for writing middleware, application structure suggestions, here we use async function as middleware you can also use commonFunction or generatorFunction which will be a little different.
This guide covers Koa topics that are not directly API related, such as best practices for writing middleware and application structure suggestions. In these examples we use async functions as middleware - you can also use commonFunction or generatorFunction which will be a little different.
## Writing Middleware