co-express-router
Use generator-based flow-control as middleware in Express.
Last updated 4 years ago by kester .
MIT · Repository · Bugs · Original npm · Tarball
$ cnpm install co-express-router 
SYNC missed versions from official npm registry.

co-express-router

co-express-router patches express routers to make them accept generator-based flow-control as middleware, using co.

Installing

npm install co-express-router

Usage

co-express-router can be used to patch Express 4.x 'app' objects and routers individually.

var express = require("express");
var app = express();

// patch the app
require("co-express-router")(app);

co-express-router does not modify the object's prototype. You may also pass a Router instance to co-express-route.

Patching will enable you to pass generators to foo.VERB, foo.use and foo.param.

app.get("/", function*(req, res, next) {
  var userCount = yield db.getUserCount();
  res.end("We have " + userCount + " registered users.");
});

Uncaught exceptions will not keep the request lingering. co-express-router will call next(err) (where err is the exception) when an exception is not handled within the generator function body.

app.get("/", function*(req, res, next) {
  var e = new Error("I am an uncaught exception");
  
  // will call next(e);
  throw e;
});

License

MIT

Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 4
Dependencies (2)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |