Nodejs请求正在挂起

时间:2013-12-27 02:01:11

标签: node.js express

我正在尝试根据用户的网址路径重定向用户,以及他们是否没有特定的Cookie设置。

如何让nodejs“无所事事”并继续?如果请求正在执行else语句,请求就会挂起。如果我删除else语句,请求也会挂起。

  app.get('/*', function (req, res) {
    if( !(typeof req.cookies['isLoggedIn'] !== 'undefined' && req.cookies['isLoggedIn'] === true ) && req.url.substring(0, 7)  != '/login/' ) {
      res.send(403, "You are not logged in");
    }else{
      //do nothing
    }
    return;
  });

2 个答案:

答案 0 :(得分:4)

您需要使用next回调来表明您的中间件没有其他任何操作。

  app.get('/*', function (req, res, next) {
    if( !(req.cookies.isLoggedIn !== void 0 && req.cookies.isLoggedIn === true) && req.url.substring(0, 7)  != '/login/' ) {
      res.send(403, "You are not logged in");
    }else{
      next();
    }
  });

答案 1 :(得分:1)

你需要输出一个。

例如

  res.send(200, "You arelogged");

否则,您的浏览器仍将等待输出。

你的意思是“继续?”