Use middleware to attach to koa context

- #configure is now private; it is called when the middleware is
  generated.
- Updated tests and example for API change