0

MEAN.js にミドルウェア (passport-http-bearer) を含めようとしていますが、Express 4 とは異なるルーティング構文を使用しています。

Express API 構文は次のとおりです。

app.get('/', function(req, res){
  res.send('hello world');
});

MEAN.js では、ルートは次のように定義されます。

app.route('/articles')
    .get(articles.list)
    .post(users.requiresLogin, articles.create);

MEAN.js ルーターにミドルウェアを含めるにはどうすればよいですか (私の場合は、トークンを確認するためのパスポート http ベアラー)。

ミドルウェアとしての http-bearer の実装例は次のとおりです。

app.get('/profile', 
  passport.authenticate('bearer', { session: false }),
  function(req, res) {
    res.json(req.user);
  });

MEAN.js でこれを行うにはどうすればよいですか?

4

1 に答える 1