docs
This commit is contained in:
parent
60eb2edb86
commit
5459fb8c55
1 changed files with 20 additions and 0 deletions
|
@ -38,6 +38,11 @@ app.use(function(next){
|
|||
|
||||
## Middleware Best Practices
|
||||
|
||||
This section covers middleware authoring best practices, such as middleware
|
||||
accepting options, named middleware for debugging, among others.
|
||||
|
||||
### Middleware options
|
||||
|
||||
When creating public middleware it's useful to conform to the convention of
|
||||
wrapping the middleware in a function that accepts options, allowing users to
|
||||
extend functionality. Even if your middleware accepts _no_ options, this is still
|
||||
|
@ -67,5 +72,20 @@ app.use(logger());
|
|||
app.use(logger(':method :url'));
|
||||
```
|
||||
|
||||
### Named middleware
|
||||
|
||||
Naming middleware is optional, however it's useful for debugging purposes to
|
||||
assign a name.
|
||||
|
||||
```js
|
||||
function logger(format){
|
||||
return function(next){
|
||||
return function *logger(){
|
||||
// ^-- name this guy
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue