我想知道在第一种情况下返回的函数被称为中间件,但是在第二种情况下返回的函数未被称为

问题描述

CASE1 ...,其中validatebody(schemas.authschema)返回的函数作为中间件执行...

router.route("/signup").post(validatebody(schemas.authschema),userscontrollers.signup);

我的第二个文件,导出验证程序的功能和模式...

module.exports={
validatebody:function(schema)
{
    return function(req,res,next)
    {
        var result=joi.validate(req.body,schema);
        if(result.error)
          return res.status(400).json(result.error);

        
        if(!req.value)
            req.value={};
        
        req.value['body']=result.value;
        next();
    }
},schemas:{
    authschema:joi.object().keys(
        {
               email:joi.string().email().required(),password:joi.string().required()
        })
}
};

现在第二种情况....在这种情况下,我什么也不会输出,并且页面会继续加载很长时间,因为函数名称从不调用第二个函数,也不会触发next()....但是在第一种情况下case ...返回的函数调用..

app.get("/users",firstfunction,secondfunction);


function firstfunction()
{
    return function(req,next)
    {
        console.log(req);
        next();
    }
}

function secondfunction(req,next)
{
    res.send("go there");
}



app.listen(3000);

解决方法

您正在传递# Tokenize all sentences in a column tokenized_sentences = [s.split() for s in df[col]] # calculate distance between 2 responses using wmd def find_similar_docs(sentence_1,sentence_2): distance = model.wv.wmdistance(sentence_1,sentence_2) return distance # find response pairs pairs_sentences = list(combinations(tokenized_sentences,2)) # get all similiarity scores between sentences list_of_sim = [] for sent_pair in pairs_sentences: sim_curr_pair = find_similar_docs(sent_pair[0],sent_pair[1]) list_of_sim.append(sim_curr_pair) ,但未调用它。您需要做

firstfunction