{"_id":"koa2-connect","_rev":"1213946","name":"koa2-connect","description":"Use Connect/Express middleware in Koa2","dist-tags":{"latest":"1.0.2"},"maintainers":[{"name":"cyrilluce","email":"cyrilluce@gmail.com"},{"name":"vkurchatkin","email":"vladimir.kurchatkin@gmail.com"}],"time":{"modified":"2021-10-13T05:47:00.000Z","created":"2017-01-11T07:56:49.727Z","1.0.2":"2017-01-12T05:49:56.003Z","1.0.1":"2017-01-11T08:32:35.577Z","1.0.0":"2017-01-11T07:56:49.727Z"},"users":{},"author":{"name":"cyrilluce","email":"cyrilluce@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/cyrilluce/koa2-connect.git"},"versions":{"1.0.2":{"name":"koa2-connect","version":"1.0.2","description":"Use Connect/Express middleware in Koa2","repository":{"type":"git","url":"git+https://github.com/cyrilluce/koa2-connect.git"},"main":"dist/index.js","author":{"name":"cyrilluce","email":"cyrilluce@gmail.com"},"contributors":[{"name":"Louis DeScioli","email":"louis.descioli@gmail.com"},{"name":"cyrilluce","email":"cyrilluce@gmail.com"}],"license":"MIT","scripts":{"test":"mocha test/index.js","test:watch":"npm run test -- --watch --reporter nyan","build":"tsc"},"files":["dist","ts","README.md"],"engines":{"node":">=4"},"devDependencies":{"koa":"^2.0.0","mocha":"^2.3.4","supertest":"^1.1.0","typescript":"^2.1.5"},"keywords":["koa","koa2","connect","express","middleware"],"gitHead":"1baec4081b236ece5488326d49f0edbd59ffca46","bugs":{"url":"https://github.com/cyrilluce/koa2-connect/issues"},"homepage":"https://github.com/cyrilluce/koa2-connect#readme","_id":"koa2-connect@1.0.2","_shasum":"cf196d70a4e6a055f717522768d26cdfc5396f7b","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.3.1","_npmUser":{"name":"cyrilluce","email":"cyrilluce@gmail.com"},"dist":{"shasum":"cf196d70a4e6a055f717522768d26cdfc5396f7b","size":3803,"noattachment":false,"key":"/koa2-connect/-/koa2-connect-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/koa2-connect/download/koa2-connect-1.0.2.tgz"},"maintainers":[{"name":"cyrilluce","email":"cyrilluce@gmail.com"},{"name":"vkurchatkin","email":"vladimir.kurchatkin@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/koa2-connect-1.0.2.tgz_1484200195786_0.023378028301522136"},"directories":{},"publish_time":1484200196003,"_cnpm_publish_time":1484200196003,"_hasShrinkwrap":false},"1.0.1":{"name":"koa2-connect","version":"1.0.1","description":"Use Connect/Express middleware in Koa2","repository":{"type":"git","url":"git+https://github.com/cyrilluce/koa2-connect.git"},"main":"index.js","author":{"name":"cyrilluce","email":"cyrilluce@gmail.com"},"contributors":[{"name":"Louis DeScioli","email":"louis.descioli@gmail.com"},{"name":"cyrilluce","email":"cyrilluce@gmail.com"}],"license":"MIT","scripts":{"test":"mocha tests.js --require mocha-babel","test:watch":"npm run test -- --watch --reporter nyan"},"files":["index.js","README.md"],"devDependencies":{"babel-plugin-transform-async-to-generator":"^6.16.0","babel-polyfill":"^6.20.0","babel-register":"^6.18.0","koa":"^2.0.0","mocha":"^2.3.4","supertest":"^1.1.0"},"keywords":["koa","koa2","connect","express","middleware"],"gitHead":"9687d0fe930881fcad2448deb379a480589e14af","bugs":{"url":"https://github.com/cyrilluce/koa2-connect/issues"},"homepage":"https://github.com/cyrilluce/koa2-connect#readme","_id":"koa2-connect@1.0.1","_shasum":"4b706bd32a64c1e79b41223ba704b064891147b0","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.3.1","_npmUser":{"name":"cyrilluce","email":"cyrilluce@gmail.com"},"dist":{"shasum":"4b706bd32a64c1e79b41223ba704b064891147b0","size":2539,"noattachment":false,"key":"/koa2-connect/-/koa2-connect-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/koa2-connect/download/koa2-connect-1.0.1.tgz"},"maintainers":[{"name":"cyrilluce","email":"cyrilluce@gmail.com"},{"name":"vkurchatkin","email":"vladimir.kurchatkin@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/koa2-connect-1.0.1.tgz_1484123553617_0.30135410907678306"},"directories":{},"publish_time":1484123555577,"_cnpm_publish_time":1484123555577,"_hasShrinkwrap":false},"1.0.0":{"name":"koa2-connect","version":"1.0.0","description":"Use Connect/Express middleware in Koa2","repository":{"type":"git","url":"git+https://github.com/cyrilluce/koa2-connect.git"},"main":"index.js","author":{"name":"cyrilluce","email":"cyrilluce@gmail.com"},"contributors":[{"name":"Louis DeScioli","email":"louis.descioli@gmail.com"},{"name":"cyrilluce","email":"cyrilluce@gmail.com"}],"license":"MIT","scripts":{"test":"mocha tests.js --require mocha-babel","test:watch":"npm run test -- --watch --reporter nyan"},"files":["index.js","README.md"],"devDependencies":{"babel-plugin-transform-async-to-generator":"^6.16.0","babel-polyfill":"^6.20.0","babel-register":"^6.18.0","koa":"^2.0.0","mocha":"^2.3.4","supertest":"^1.1.0"},"keywords":["koa","koa2","connect","express","middleware"],"gitHead":"81f758c80f71123ce4e66211c45292923d0a8c17","bugs":{"url":"https://github.com/cyrilluce/koa2-connect/issues"},"homepage":"https://github.com/cyrilluce/koa2-connect#readme","_id":"koa2-connect@1.0.0","_shasum":"fc0b966a911533fb342ce1c3771609b848096fad","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.3.1","_npmUser":{"name":"cyrilluce","email":"cyrilluce@gmail.com"},"dist":{"shasum":"fc0b966a911533fb342ce1c3771609b848096fad","size":2535,"noattachment":false,"key":"/koa2-connect/-/koa2-connect-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/koa2-connect/download/koa2-connect-1.0.0.tgz"},"maintainers":[{"name":"cyrilluce","email":"cyrilluce@gmail.com"},{"name":"vkurchatkin","email":"vladimir.kurchatkin@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/koa2-connect-1.0.0.tgz_1484121409478_0.8966735654976219"},"directories":{},"publish_time":1484121409727,"_cnpm_publish_time":1484121409727,"_hasShrinkwrap":false}},"readme":"# koa2-connect\r\nBase on [koa-connect](https://github.com/vkurchatkin/koa-connect), improve to support webpack-dev-middleware and webpack-hot-middleware.\r\nUse [Express](https://github.com/strongloop/express)/[Connect](https://github.com/senchalabs/connect) middleware with Koa.\r\n\r\n## Warning\r\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.\r\n\r\n### Always use `next`\r\nExpress middlewares need to declare and invoke the `next` callback appropriately for the koa-connect integration to work correctly.\r\n\r\n### For library authors\r\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`.\r\n\r\n## Installation\r\n\r\n```sh\r\nnpm install koa2-connect\r\n```\r\n\r\n## Usage\r\nSee `examples/` for more real-world examples.\r\n\r\n```javascript\r\nconst Koa = require('koa')\r\nconst c2k = require('koa2-connect')\r\n\r\n// A generic Express-style middleware function\r\nfunction connectMiddlware (req, res, next) {\r\n  res.writeHead(200, {'Content-Type': 'text/plain'})\r\n  res.end('From the Connect middleware')\r\n  next()\r\n}\r\n\r\n// A generic Koa v2 middlware, without async/await\r\nfunction koaMiddlware(ctx, next) {\r\n  return next()\r\n    .then(() => {\r\n      // The control flow will bubble back to here, like usual\r\n    })\r\n    .catch((err) => {\r\n      // Error handling from downstream middleware, like usual\r\n    })\r\n}\r\n\r\n// A generic Koa v2 middlware with async/await\r\nasync function koaMiddleware(ctx, next) {\r\n  try {\r\n    await next();\r\n  } catch (e) {\r\n    // Normal error handling\r\n  }\r\n  // Normal control flow\r\n}\r\n\r\nconst app = new Koa()\r\napp.use(koaMiddlware)\r\napp.use(c2k(connectMiddlware))\r\napp.use((ctx, next) => {\r\n  console.log('It will continue on to here')\r\n})\r\n\r\napp.listen(3000)\r\n```\r\n\r\n## Testing\r\nTests are in `tests.js` and are made with the [Mocha](https://mochajs.org) framework. You can run them with `npm test` or `npm run test:watch`\r\n\r\n## License\r\nMIT\r\n","_attachments":{},"homepage":"https://github.com/cyrilluce/koa2-connect#readme","bugs":{"url":"https://github.com/cyrilluce/koa2-connect/issues"},"license":"MIT"}