Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

middleware without path doesn't work #161

Closed
letchik opened this issue Aug 13, 2015 · 2 comments
Closed

middleware without path doesn't work #161

letchik opened this issue Aug 13, 2015 · 2 comments

Comments

@letchik
Copy link

letchik commented Aug 13, 2015

I have a simple code

let router = new Router();
router.get('/',
  function *(next) {
    ...
  }
);
router.use(
  function *(next) {
    console.log('middleware');
    ...
    yield next;
  }
);

it doesn't work in this case, middlware didn't call
the other way works fine

router.use('/',
  function *(next) {
    console.log('middleware');
    ...
    yield next;
  }
);
@divmgl
Copy link

divmgl commented Aug 13, 2015

This is a simple bug in the source code. Here is the patch.

if (matched.route) {
  this.route = matched.route;
  this.captures = this.route.captures(path, this.captures);
  this.params = this.route.params(path, this.captures, this.params);

  debug('dispatch %s %s', this.route.path, this.route.regexp);

  next = matched.route.middleware.call(this, next);
}

if (matched.middleware) {
  for (var i = 0, l = matched.middleware.length; i < l; i++) {
    next = matched.middleware[i].call(this, next);
  }
}

@divmgl
Copy link

divmgl commented Sep 5, 2015

@letchik your code is working in the master branch. You may be doing something wrong in your setup.

ruiquelhas pushed a commit to seegno-forks/koa-router that referenced this issue Oct 16, 2015
- Fixes ZijianHe#161, fixes ZijianHe#155, fixes ZijianHe#156.
- Removes dependency on koa-compose.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants