Skip to content
Permalink
Browse files
Add generator support to the middleware stack
  • Loading branch information
kenrick committed Jan 19, 2015
1 parent 40f7a8e commit 8dac72bc9b11a71ed52a54bf35768d2ead912238
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
@@ -4,6 +4,7 @@

var pathRegexp = require('path-to-regexp');
var debug = require('debug')('express:router:layer');
var co = require('co');

/**
* Module variables.
@@ -73,6 +74,10 @@ Layer.prototype.handle_error = function handle_error(error, req, res, next) {
Layer.prototype.handle_request = function handle(req, res, next) {
var fn = this.handle;

if(fn.constructor.name === 'GeneratorFunction') {
fn = co.wrap(fn);
}

if (fn.length > 3) {
// not a standard request handler
return next();
@@ -28,7 +28,9 @@
],
"dependencies": {
"accepts": "~1.2.2",
"co": "^4.1.0",
"content-disposition": "0.5.0",
"cookie": "0.1.2",
"cookie-signature": "1.0.5",
"debug": "~2.1.1",
"depd": "~1.0.0",
@@ -37,6 +39,7 @@
"finalhandler": "0.3.3",
"fresh": "0.2.4",
"media-typer": "0.3.0",
"merge-descriptors": "0.0.2",
"methods": "~1.1.1",
"on-finished": "~2.2.0",
"parseurl": "~1.3.0",
@@ -47,10 +50,8 @@
"send": "0.11.0",
"serve-static": "~1.8.0",
"type-is": "~1.5.5",
"vary": "~1.0.0",
"cookie": "0.1.2",
"merge-descriptors": "0.0.2",
"utils-merge": "1.0.0"
"utils-merge": "1.0.0",
"vary": "~1.0.0"
},
"devDependencies": {
"after": "0.8.1",

1 comment on commit 8dac72b

@Fonger
Copy link

@Fonger Fonger commented on 8dac72b Apr 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't catch the error here. If there's an error in the generator function, it will disappear and end up timeout.

Please sign in to comment.