koa-connect
Advanced tools
Comparing version 2.0.0 to 2.0.1
{ | ||
"name": "koa-connect", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Use Connect/Express middleware in Koa", | ||
@@ -9,3 +9,3 @@ "repository": "vkurchatkin/koa-connect", | ||
"contributors": [ | ||
"Louis DeScioli <louis.descioli@gmail.com>" | ||
"Louis DeScioli (https://descioli.design)" | ||
], | ||
@@ -12,0 +12,0 @@ "license": "MIT", |
@@ -1,12 +0,18 @@ | ||
# koa-connect | ||
# koa-connect [![npm package badge][npm badge]][npm] | ||
Use [Express](https://github.com/strongloop/express)/[Connect](https://github.com/senchalabs/connect) middleware with Koa. | ||
[npm badge]: https://badge.fury.io/js/koa-connect.svg | ||
[npm]: https://www.npmjs.com/package/koa-connect | ||
Use [Express](https://github.com/strongloop/express)/[Connect](https://github.com/senchalabs/connect) middleware with [Koa](https://github.com/koajs/koa). | ||
## Warning | ||
It 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. | ||
### Always use `next` | ||
### Always use `next` middleware parameter | ||
Express middlewares need to declare and invoke the `next` callback appropriately for the koa-connect integration to work correctly. | ||
### For library authors | ||
If 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`. | ||
@@ -17,8 +23,9 @@ | ||
```sh | ||
npm install koa-connect@next | ||
npm install koa-connect | ||
``` | ||
## Usage | ||
See `examples/` for more real-world examples. | ||
See [`examples/`](./examples) for more practical usage. | ||
```javascript | ||
@@ -29,4 +36,4 @@ const Koa = require('koa') | ||
// A generic Express-style middleware function | ||
function connectMiddlware (req, res, next) { | ||
res.writeHead(200, {'Content-Type': 'text/plain'}) | ||
function connectMiddlware(req, res, next) { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }) | ||
res.end('From the Connect middleware') | ||
@@ -36,3 +43,3 @@ next() | ||
// A generic Koa v2 middlware, without async/await | ||
// A generic Koa middlware, without async/await | ||
function koaMiddlware(ctx, next) { | ||
@@ -43,3 +50,3 @@ next() | ||
}) | ||
.catch((err) => { | ||
.catch(err => { | ||
// Error handling from downstream middleware, like usual | ||
@@ -49,6 +56,6 @@ }) | ||
// A generic Koa v2 middlware with async/await | ||
// A generic Koa middlware with async/await | ||
async function koaMiddleware(ctx, next) { | ||
try { | ||
await next(); | ||
await next() | ||
} catch (e) { | ||
@@ -71,5 +78,7 @@ // Normal error handling | ||
## Testing | ||
Tests 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` | ||
## License | ||
MIT |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
24979
79
0