1

これはおそらく非常に単純な質問ですが、1 時間以上グーグルで検索しましたが、何も見つかりませんでした。また、リクエスト オブジェクトを印刷しようとしましたが、何も役に立ちません。

grunt-contrib-connect ミドルウェア定義内でクライアント要求のデータまたは本文を取得するにはどうすればよいですか?

connect: {
  main: {
    options: {
      hostname: "0.0.0.0",
      port: 8080,
      /**
       *  These are the mocked out backends for various endpoints
       */
      middleware: function(connect, options, middlewares) {
        middlewares.unshift(function(req, res, next) {
          if (req.url !== '/v1/accounts/_findEmail') {
            return next();
          }

          // ********
          // How do I get the data content of the request?
          var data = req.data; // Is undefined
          // ********

          if (data && data.email === 'taken@email.com') {
            res.writeHead(200, {"Content-Type": "application/json"});
            res.write(JSON.stringify({email:"found"}));
          } else {
            res.writeHead(404, {"Content-Type": "application/json"});
            res.write(JSON.stringify({email:"not found"}));
          }

          res.end();
        });

        return middlewares;
      }

    }
  }
}
4

2 に答える 2