Cloud Functions模拟器中未显示“写入Cloud Firestore(模拟器)”

时间:2019-11-06 18:01:38

标签: firebase google-cloud-firestore google-cloud-functions firebase-hosting firebase-tools

我正在为Vue应用程序使用Firebase托管/ Firestore /功能。托管+ Firestore运行正常。 现在,我想添加更多功能,并想添加功能。为了在本地进行测试,我启动了一个Firestore,并且可以运行所有3个模拟器。 现在,当我启动仿真器并转到托管仿真器时,我可以插入一条记录,该记录也会显示在生产数据库中,但不会触发该功能。它是onCreate。 我部署了该功能,并且工作正常。我可以看到console.log()。

为什么本地/生产写入不触发云功能?

功能如下:

export const sendWelcomeEmail = functions.firestore.document('/activeJobsTestDB/{jobId}').onCreate((data,context) => {
  const inputRecord = data.data();
  console.log('here' + inputRecord);
  // const mailOptions = { 
  //   from: '"Spammy Corp." <noreply@firebase.com>',
  //   to: inputRecord.email,
  // };

});
i  Starting emulators: ["functions","firestore","hosting"]
⚠  Your requested "node" version "8" doesn't match your global version "12"
✔  functions: Emulator started at http://localhost:5001
i  firestore: Serving ALL traffic (including WebChannel) on http://localhost:8080
⚠  firestore: Support for WebChannel on a separate port (8081) is DEPRECATED and will go away soon. Please use port above instead.
i  firestore: Emulator logging to firestore-debug.log
✔  firestore: Emulator started at http://localhost:8080
i  firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080
i  hosting: Serving hosting files from: dist
✔  hosting: Local server: http://localhost:5000
✔  hosting: Emulator started at http://localhost:5000
i  functions: Watching "/Volumes/Work/playground/sforce-job/sforce-jobs/functions" for Cloud Functions...
>  here
✔  functions[sendWelcomeEmail]: firestore function initialized.
✔  All emulators started, it is now safe to connect.

我转到localhost:5000并可以根据需要使用我的应用程序,但未触发该功能。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

在这里回答自己,以防有人面对:我意识到无法将Cloud Firestore与本地Cloud Function连接起来。简单的方法是拥有一个看起来像DocumentSnapshot的json,然后通过外壳将其传递给函数。使用:

(
(fn abc [& cs]
  (let [ fs (first (take 1 (apply map (fn [& vs] vs) cs)))
         fi (apply min fs)
         fx (apply max fs)]
    (if 
      (= fi fx) fi
      (for [n (range (count fs)) :when (= fi (nth fs n))]
         (apply abc (concat (take n cs) (vector (rest (nth cs n))) (drop (inc n) cs)))))))

[1 2 3 4 5 6 7] [4 19])

其他方法是在Firestore模拟器中创建本地数据库,将云功能指向Firestore模拟器。 然后运行托管模拟器,所有3个模拟器都应该运行良好。