次のように定義されたサーバーがあります。
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
私が望むようにする方法はありますか?