Add koa compatible middleware function