{"name":"koa-connect","version":"1.0.0","description":"Use connect and express middleware in koa","main":"index.js","author":{"name":"Vladimir Kurchatkin","email":"vladimir.kurchatkin@gmail.com"},"respository":"vkurchatkin/koa-connect","license":"MIT","devDependencies":{"koa":"^0.10.0"},"dependencies":{"connect":"^2.25.7"},"_id":"koa-connect@1.0.0","_shasum":"0aecf10df15f32526ad15815115cb3d40aece705","_from":".","_npmVersion":"1.4.9","_npmUser":{"name":"vkurchatkin","email":"vladimir.kurchatkin@gmail.com"},"maintainers":[{"name":"vkurchatkin","email":"vladimir.kurchatkin@gmail.com"}],"dist":{"shasum":"0aecf10df15f32526ad15815115cb3d40aece705","tarball":"http://registry-npm.ywwl.com/koa-connect/download/koa-connect-1.0.0.tgz","integrity":"sha512-NQ7H8gBh90LLi8Fq0i+gdS9ELYiu7Yplytsdh9xVYdKhjpcU82DOIq7h3recWHhQVwP1RWCAgJ76EVeMRe9RTw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQClLFGwFmhX6TOQhADUqM9xjWjEaPxmtGPL+hzAnuzJ4gIgC9Tj0S0kytdeutNKbVFOgvIJMYxr9e59Rm+uU08t6TQ="}],"size":1067,"noattachment":false,"key":"/koa-connect/-/koa-connect-1.0.0.tgz"},"directories":{},"readme":"# koa-connect [![npm package badge][npm badge]][npm]\n\n[npm badge]: https://badge.fury.io/js/koa-connect.svg\n[npm]: https://www.npmjs.com/package/koa-connect\n\nUse [Express](https://github.com/strongloop/express)/[Connect](https://github.com/senchalabs/connect) middleware with [Koa](https://github.com/koajs/koa).\n\n## Warning\n\nIt is **highly** recommended to use a Koa-specific middleware instead of trying to convert an Express version when they're available. There is a non-trivial difference in the Koa and Express designs and you will inevitably run into some issues. This module is a workaround for the specific cases where the differences can be ignored. Additionally, it also enables library authors to write 1 version of their HTTP middleware.\n\n### Always use `next` middleware parameter\n\nExpress middlewares need to declare and invoke the `next` callback appropriately for the koa-connect integration to work correctly.\n\n### For library authors\n\nIf you're attempting to write a framework-agnostic middleware library, be sure to use only core HTTP methods and not any Express-dependent APIs like `res.send`.\n\n## Installation\n\n```sh\nnpm install koa-connect\n```\n\n## Usage\n\nSee [`examples/`](./examples) for more practical usage.\n\n```javascript\nconst Koa = require('koa');\nconst c2k = require('koa-connect');\n\n// A generic Express-style middleware function\nfunction connectMiddlware(req, res, next) {\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('From the Connect middleware');\n  next();\n}\n\n// A generic Koa middlware, without async/await\nfunction koaMiddlware(ctx, next) {\n  next()\n    .then(() => {\n      // The control flow will bubble back to here, like usual\n    })\n    .catch((err) => {\n      // Error handling from downstream middleware, like usual\n    });\n}\n\n// A generic Koa middlware with async/await\nasync function koaMiddleware(ctx, next) {\n  try {\n    await next();\n  } catch (e) {\n    // Normal error handling\n  }\n  // Normal control flow\n}\n\nconst app = new Koa();\napp.use(koaMiddlware);\napp.use(c2k(connectMiddlware));\napp.use((ctx, next) => {\n  console.log('It will continue on to here');\n});\n\napp.listen(3000);\n```\n\n## Contributing\n\n### Developing\n\n`npm start` starts the TypeScript compiler in watch mode. Code will be auto-formatted upon commit as part of the Prettier + lint-staged + Husky setup.\n\n### Building\n\n`npm run build` produces the types declaration file and JavaScript file for publishing.\n\n### Testing\n\n`npm test` runs the tests. Tests are in `tests.js` and are made with the [Mocha](https://mochajs.org) framework.\n\nUse `npm run test:watch` in conjunction with `npm start` to automatically re-run the tests when the source changes.\n\n## License\n\nMIT\n","publish_time":1408464139354,"_cnpm_publish_time":1408464139354,"dist-tags":{"latest":"2.1.1"}}