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

Several middlewares executed with nested routes #410

Closed
farwayer opened this issue Dec 21, 2017 · 1 comment
Closed

Several middlewares executed with nested routes #410

farwayer opened this issue Dec 21, 2017 · 1 comment

Comments

@farwayer
Copy link

farwayer commented Dec 21, 2017

const nested = new Router()
  .get('/', (ctx, next) => {
    ctx.body = "root";
    console.log("root");
    return next();
  })
  .get('/test', (ctx, next) => {
    ctx.body = "test";
    console.log("test");
    return next();
  });

const router = new Router()
  .use(nested.routes());

GETting /test prints to console:

root
test

It is really unexpected behaviour!
Maybe related to #369 because the problem is with setting (.*) prefix in Router.use() function.

One more wrong thing with this behaviour: GETting /xxx will execute root although it should throw 404.

router.use('', nested.routes())

can be used as workaround.

jbielick added a commit that referenced this issue Jan 20, 2018
fixes what looks like a regression in 8665620 in which `path` inside of
`.use()` is defaulted to a wildcard `(.*)` instead of remaining
undefined while the line:

if (path) nestedLayer.setPrefix(path)

runs.

https://github.com/alexmingoia/koa-router/blob/840591d4f660ddde98aedc689dea862a7e63f55b/lib/router.js#L265

This fixes #369 and #410
A test case has been added.
@jbielick
Copy link
Collaborator

This should be fixed in 7.4.0

ff15285

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