How to wrap multiple middleware functions into one?

前端 未结 1 1944
没有蜡笔的小新
没有蜡笔的小新 2021-01-18 12:07

I have a number of middleware functions similar to the following:

function validate(req, res, next) {
  req.validationError = new Error(\'invalid\');
}

func         


        
1条回答
  •  走了就别回头了
    2021-01-18 13:09

    try with following code

    app.use('/', [validate, checkValid,respond]);
    

    OR

    var middleware = [validate, checkValid,respond];
    
    app.use('/', middleware );
    

    Need to placed all function in that series as your requirement of execution.

    Thanks

    0 讨论(0)
提交回复
热议问题