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

Parent middleware is called several times #184

Closed
tearwyx opened this issue Oct 2, 2015 · 0 comments
Closed

Parent middleware is called several times #184

tearwyx opened this issue Oct 2, 2015 · 0 comments

Comments

@tearwyx
Copy link

tearwyx commented Oct 2, 2015

Hi, I have this sample code:

const parentRouter = new Router();
const nestedRouter = new Router();

nestedRouter
    .get('/first-nested-route', function *(next) {
        console.log('first nested middleware');

        yield next;
    })

    .get('/second-nested-route', function *(next) {
        console.log('second nested middleware');

        yield next;
    })

    .get('/third-nested-route', function *(next) {
        console.log('third nested middleware');

        yield next;
    });

parentRouter.use('/parent-route',
    function *(next) {
        console.log('parent middleware');

        yield next;
    },
    nestedRouter.routes()
);

app.use(parentRouter.routes());

I requested a /parent-route/first-nested-route and got this debug output:

koa-router GET /parent-route/first-nested-route +5s
koa-router test /parent-route /^\/parent-route(?:\/(?=$))?(?=\/|$)/i +2ms
koa-router test /parent-route /^\/parent-route(?:\/(?=$))?(?=\/|$)/i +1ms
koa-router test /parent-route /^\/parent-route(?:\/(?=$))?(?=\/|$)/i +0ms
koa-router test /parent-route/first-nested-route /^\/parent-route\/first-nested-route(?:\/(?=$))?$/i +0ms
koa-router test /parent-route/second-nested-route /^\/parent-route\/second-nested-route(?:\/(?=$))?$/i +0ms
koa-router test /parent-route/third-nested-route /^\/parent-route\/third-nested-route(?:\/(?=$))?$/i +1ms
koa-router dispatch /parent-route/first-nested-route /^\/parent-route\/first-nested-route(?:\/(?=$))?$/i +0ms
koa-router dispatch /parent-route /^\/parent-route(?:\/(?=$))?(?=\/|$)/i +1ms
koa-router dispatch /parent-route /^\/parent-route(?:\/(?=$))?(?=\/|$)/i +0ms
koa-router dispatch /parent-route /^\/parent-route(?:\/(?=$))?(?=\/|$)/i +0ms

And additional output:

parent middleware
parent middleware
parent middleware
first nested middleware

I use the koa-router@5.2.2. Why is parent middleware called several times? Isn't that a bug? Thank you for any inquiries.

ruiquelhas pushed a commit to seegno-forks/koa-router that referenced this issue Oct 16, 2015
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

1 participant