Skip to content

请教一个关于中间件的运行流程问题,函数被重复执行了; #25

@zeyongTsai

Description

@zeyongTsai

some code...

app.use(function *(next){
console.log("-+-+-+-+-+-+");
console.log(this.method);
yield next;
this.body = "hello world world world!";
console.log("------");
});

app.use(route.get('/products',function *(){
console.log("hahaha");
console.log(this.method);
console.log("hehehehe");
}));

app.use(function *(){
console.log('999');
this.body = "hello world!";
console.log(this.method);
console.log("++++++");
});

other code...
控制台的结果:
image

我想请问的是:为什么写在route前面的函数被调用了两次呢?如果放在后面的话,倒是没有这个问题;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions