Nodejs请求挂起
我试图根据他们的urlpathredirect一个用户,如果他们没有一个特定的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; });
您需要使用next
callback来表明您的中间件没有任何其他的事情要做。
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(); } });
你需要把输出。
例如
res.send(200, "You arelogged");
否则,您的浏览器仍然会等待输出。
你是什么意思“继续?”