使用express.js创建的node.js REST服务器,邻这项工作的一部分,我也创建一个简单的会话系统。我有3个模块:将功能传递给下一个功能,根据情况进行启动。
- app.js
- highscoreMan.js
- userSession.js
为http://localhost/api/highscores
的app.js网址现在给出的参数调用userSession:
//Get all highscores
app.get('/api/highscores', function (req, res) {
userSession.checkValidity(req.query['username'], req.query['sessionid'], highscoreMan.getAll(req, res));
});
然而,在checkValidity我传递函数被自动调用:
function checkValidity(username, sessionId, callback) {
userSession.findOne({ userid: username, sessionid: sessionId }, function (err, result) {
if (err) {
console.log(err);
}
if(result) {
callback;
}
});
}
我只想运行函数传递给我从数据库中获取正确的结果(其他检查将在以后的会议日期等附加)。我将如何做到这一点?
这出色的作品,! – nenne 2013-04-06 07:51:03