2016-04-12 13 views
0

こんにちは、私のURLは/ getSystemInfoで始まります。ライセンスがない場合、askForLicenseページにリダイレクトされますが、このリダイレクトは機能しません。Node.jsミドルウェアのリダイレクトが機能しない

app.get('/getSystemInfo', isAuthenticated, hasLicense, function(req, res) 
{ 
    logger.debug('querying iStar status'); 
    ... 
} 

var isAuthenticated = function(req, res, next) 
{ 
    if(req.isAuthenticated()) { 
     console.log("Very good, you are logged in ..."); 
     return next(); 
    } else { 
     console.log("Sorry, you are NOT logged in yet ..."); 
     res.send(401); 
    } 
} 

var hasLicense = function(req, res, next) 
{ 
    // queryLicense.py will return error is no license 
    var getLicense = exec('queryLicense.py', 
        function (error, stdout, stderr) { 
         if (error !== null) { 
          console.log('License exec error: ' + error); 
          res.redirect('/askForLicense'); 
         } else { 
          console.log("---- good, you have license ----\n"); 
          return next(); 
         } 
        } 
    ); 
}; 

app.get('/askForLicense', function(req, res) 
{ 
    console.log("---- Notice: need license ----"); 
    res.sendfile(path.resolve('../client/askForLicense.html')); 
}); 

コンソール出力はこのようなものです:コマンドが失敗しました::

非常に良い、あなたがで...

ライセンスexecがエラーログに記録されます。エラー/ binに/ shの-c getLicense.py

しかし、私は/ askForLicenseのログインが表示されません、なぜですか? 多くの感謝!

+0

不要に到達していません次に戻るには、次のようにしてください。 – JordanHendrix

答えて

0

あなたのミドルウェア機能は、この順序で呼び出され、

/getSystemInfo, isAuthenticated, hasLicense, /askForLicense 

あなたがhasLicense、ミドルウェア内部exec("getLicenese.py")を呼び出しているし、それがエラーをスローしますので、呼び出しは次のミドルウェア/askForLicense

+0

どうすればいいですか? – user3552178

+0

シェルターミナルで 'getLicense.py'が失敗する理由を確認してください。ファイルに実行権限がない可能性があります。 (または)exec関数にcmdとして 'python'を渡し、ファイル名に' getLicense.py'を余分な引数として与える必要があるかもしれません。 –

+0

はお試しいただきありがとうございます! – user3552178

関連する問題