Javascript 邮递员说;错误:无法处理请求";将请求过帐到Firebase功能时

Javascript 邮递员说;错误:无法处理请求";将请求过帐到Firebase功能时,javascript,node.js,firebase,google-cloud-firestore,google-cloud-functions,Javascript,Node.js,Firebase,Google Cloud Firestore,Google Cloud Functions,这是我的职责。当我部署并尝试在Postman上发布请求时,如下所示: exports.createNotice = functions.https.onRequest((req, res) => { if (req.method !== "POST") { return res.status(400).json({ error: "Method not allowed" }); } const newNotice = {

这是我的职责。当我部署并尝试在Postman上发布请求时,如下所示:


exports.createNotice = functions.https.onRequest((req, res) => {
  if (req.method !== "POST") {
    return res.status(400).json({ error: "Method not allowed" });
  }

  const newNotice = {
    body: req.body.body,
    userHandle: req.body.userHandle,
    createdAt: admin.firestore().Timestamp.fromData(new Date()),
  };
  admin
    .firestore()
    .collection("notices")
    .add(newNotice)
    .then((doc) => {
      res.json({ message: `document ${doc.id} created successfully` });
    })
    .catch((err) => {
      res.status(500).json({ error: "something went wrong" });
      console.error(err);
    });
});

它显示错误:无法处理请求。我想让它更新我在Firebase上的数据库。创建新的通知集合。有人能帮我吗?

在创建代码时,代码中有两个错误

  • 有一个输入错误:方法是
    fromDate()
    而不是
    fromData()
  • 您需要按如下方式调用它:
    admin.firestore.Timestamp.fromDate(new Date())

  • 另外请注意,对于代码中的第一个块,您应该执行以下操作。无需使用
    返回
    ,请参阅


    您是否在云功能控制台中发现任何错误?
    {
        "body": "New Notice",
        "userHandle": "user"
    }
    
      if (req.method !== "POST") {
        res.status(400).json({ error: "Method not allowed" });
      }