{"name":"koa-connect","version":"2.1.0","description":"Use Connect/Express middleware in Koa","repository":{"type":"git","url":"git+https://github.com/vkurchatkin/koa-connect.git"},"main":"index.js","types":"index.d.ts","author":{"name":"Vladimir Kurchatkin","email":"vladimir.kurchatkin@gmail.com"},"contributors":[{"name":"Louis DeScioli","url":"https://descioli.design"}],"license":"MIT","scripts":{"start":"tsc --watch","build":"tsc -p tsconfig-build.json","test":"mocha -r ts-node/register tests.ts","test:watch":"npm run test -- --watch --watch-extensions ts --reporter nyan"},"devDependencies":{"@types/body-parser":"^1.19.0","@types/koa":"^2.0.46","@types/mocha":"^7.0.2","@types/node":"^10.9.2","@types/supertest":"^2.0.9","body-parser":"^1.19.0","husky":"^4.2.5","koa":"^2.0.0","lint-staged":"^10.2.9","mocha":"^2.3.4","prettier":"^2.0.5","supertest":"^1.1.0","ts-node":"^8.10.2","typescript":"^3.0.1"},"keywords":["koa","connect","express","middleware"],"husky":{"hooks":{"pre-commit":"lint-staged"}},"lint-staged":{"!(*.d).ts":"prettier --single-quote --write","*.md":"prettier --write"},"gitHead":"3f7c4020604895f6693c622fd0b48b377005f5da","bugs":{"url":"https://github.com/vkurchatkin/koa-connect/issues"},"homepage":"https://github.com/vkurchatkin/koa-connect#readme","_id":"koa-connect@2.1.0","_nodeVersion":"10.16.3","_npmVersion":"6.13.7","dist":{"integrity":"sha512-O9pcFafHk0oQsBevlbTBlB9co+2RUQJ4zCzu3qJPmGlGoeEZkne+7gWDkecqDPSbCtED6LmhlQladxs6NjOnMQ==","shasum":"16bce0a917c4cb24233aaac83fbc5b83804b4a1c","tarball":"http://registry-npm.ywwl.com/koa-connect/download/koa-connect-2.1.0.tgz","fileCount":16,"unpackedSize":17075,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJe9lGqCRA9TVsSAnZWagAA3fUP+QGkMBgBjPv7oLtkwkPS\nVq+LdC78uo5DaaRAc++Y+yjIg33+n7FJp9P46IpvlzMcPkZEpmX1TN4UN5b/\nqIJGR76JpzG0xCThSoophPb5h/O9AH/QNwshQTkHAv8tKawSH7UhUs81fU+w\n+hWvIMZaK2mM3pg4jW6dTXs467IZxYN04HsVa4w2Tc4e8tGD9FDJN6kxTom4\nfaSf8AmgcA540kUMeaEf3UHtxRYfwCNatOSw2b3rrnMpUptj+HUIp94i03ZS\naud9EL4bUd0Oio+8j6nKsYneMG9rwOKbeq4NuXl6eFHZYWuiERtWaBmYftVd\n2AnmYFt4bxrDk2+1pUTjVCSCMAzJSNjd/OCzYSqWQFOHSZnrHpKqcNvMgo0l\nXC8yJ5mMOwWcUpAhXK5ckqGPnfGRyIbJ1hYBZEzL89P/Vv9m8lClQ9HJIB5L\nhC1j2dNwBGYOXXaMl9czlH/+f/b4ggmlRm/sJfCp+nmkrTeZwUUsuaaGyr//\nSQIfJnGdY6ANhtEZSNQlaToPW7gxmhNZtlflyyG4H16qLzEsBk0zpbQ1MRxe\nu7fvoMm4nLpoD4VyUrGC5CLEDkQ+feF+oxxvdN0bAE6pf5ZnDih8j+4P6OoC\ndFFO4vqWJQ4CtzwA8r1YSO4BdvNvT2d4ZZyVYSLHQpy1Ra2acEMbzVXj169v\n64DS\r\n=ALP0\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGms1faepESFwgh/yEIQgxX9COD7/jlRHLw5cMh4keggAiBlJj4FjvJW5tf5r5H0aZ++7LGPUUr4YM4PHqhtc6X5qQ=="}],"size":5374,"noattachment":false,"key":"/koa-connect/-/koa-connect-2.1.0.tgz"},"maintainers":[{"name":"lourd","email":"louis@grovelabs.io"},{"name":"vkurchatkin","email":"vladimir.kurchatkin@gmail.com"}],"_npmUser":{"name":"lourd","email":"louis.descioli@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/koa-connect_2.1.0_1593201066165_0.13624625029081217"},"_hasShrinkwrap":false,"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":1593201066374,"_cnpm_publish_time":1593201066374,"dist-tags":{"latest":"2.1.1"}}