私はそれを追加するルート上で動作するセキュリティチェックミドルウェアを設定しようとしています。エクスプレスミドルウェアを使用し、ルートにres.localデータを渡す
ミドルウェアが
function SecurityCheckHelper(req, res, next){
apiKey = req.query.apiKey;
security.securityCheck(apiKey).then(function(result) {
res.locals.Security = result.securitycheck;
console.log(res.locals.Security);
});
return next(); // go to routes
};
ルート
app.get('/settings', SecurityCheckHelper,function(req, res, next) {
console.log(res.locals);
});
ITSは比較的単純私は/settings
ルートに(真/偽を返す)result.securitycheck
に合格しようとしています。しかしres.locals
は空のオブジェクトを返しています
あなたsecurityCheckは非同期で、あなたの即座の次返すので、これは..ですあなたの、その後の内部で、次を置く。..素晴らしい@Keith – Keith
!あなたは頭の上にそれを釘付けにしたので、質問に答えることができるので、私はあなたに信用を与えることができます:D – Charles