middleware continues after the next

0

I have the following question with a middleware, if the middleware works the following way:

function middle(variable){
  // codigo codigo
  return function(req, res, next){

    if(hrk !== 'jfk'){
      if(variable){
        next();
      }
    }


    // codigo
    // y
    // mas codigo

    next();
  }
}

and a route works on this route:

router.get('/lala', middle(true), miControllador) 

The problem is that it gets to where the variable that is a Boolean exists and is in true but the problem is that it does not pass to the next function middle which would be miControllador .

    
asked by soldat25 08.03.2016 в 20:03
source

1 answer

0

Try using return next() :

function middle(variable){
  // codigo codigo
  return function(req, res, next){

    if(hrk !== 'jfk'){
      if(variable){
        return next();
      }
    }


    // codigo
    // y
    // mas codigo

    return next();
  }
}
    
answered by 08.03.2016 / 20:18
source