Firestore触发功能不会在本地仿真器中记录(触发),当我部署它们时,它们会记录并正常工作。
const admin = require("firebase-admin");
const serviceAccount = require('./firebase-adminsdk-.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://find-place.firebaseio.com"
});
const functions = require('firebase-functions');
功能本身
exports.emergencyCreated = functions.firestore
.document('emergencies/{emergenciesId}')
.onCreate((snap, context) => {
console.info('created')
const emergencyData = snap.data();
console.log(emergencyData)
// perform desired operations ...
});
终端日志
i emulators: Starting emulators: functions, firestore
+ functions: Using node@10 from host.
+ functions: Emulator started at http://localhost:5001
i firestore: Serving ALL traffic (including WebChannel) on http://localhost:5004
! firestore: Support for WebChannel on a separate port (5005) 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:5004
i firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:5004
i functions: Watching "C:\Users\master\Desktop\find-safe-place\functions" for Cloud Functions...
+ functions[sendInviteToApp]: http function initialized (http://localhost:5001/find-safe-place/us-
central1/sendInviteToApp).
+ functions[emergencyCreated]: firestore function initialized.
+ All emulators started, it is now safe to connect.
在Vue客户端上配置
import firebase from 'firebase/app'
import 'firebase/firestore'
import 'firebase/database'
import 'firebase/firebase-auth'
import 'firebase/messaging'
import 'firebase/functions'
firebase.functions().useFunctionsEmulator('http://localhost:5001');
Package.json
"firebase-admin": "^8.8.0",
"firebase-functions": "^3.3.0",