次のように定義されたサーバーがあります。
app.get('/', function(req, res) {
// gets something
}
app.post('/', function(req, res) {
// updates something, need to be authenticated
}
ここpostで、認証されたユーザーに対してのみアクションを実行したいので、次のようにauthそれらの間にミドルウェアを追加します。
app.get('/', function(req, res) {
// gets something
}
app.use('/', function(req, res) {
// check for authentication
}
app.post('/', function(req, res) {
// updates something, need to be authenticated
}
このようにGETしてPOST、ユーザーを認証する必要があります。
app.use問題は、Express がミドルウェアに入らないことです。すべてのルートapp.useの前にミドルウェアを配置すると、機能します。app.VERB
私が望むようにする方法はありますか?