[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Latest commit

 

History

History

08-decorators

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

In Koa, all middleware are essentially decorators for all following middleware:

app.use(function* decorator(function (subapp) {
  // do something before subapp executes
  yield* subapp;
  // do something after subapp executes
}))

app.use(function* subapp(next) {
  this.response.body = 'hello world';
})

For more information on decorators, look up "decorator functions" or the "decorator pattern". I would add a link to a good resource, but I don't think any of the ones I've found yet are that good.

Exercise

Create a middleware that escapes all the HTML entities in the response.