У меня есть этот вызов export const notificationsCall = functions.https.onCall((data, context) => { }
Когда я его развертываю и вызываю из моего iOS приложения functions.httpsCallable("getNotifications").call() { (result, error) in }
, все работает нормально, и я получаю правильный ответ.
Однако, когда я запускаю firebase emulators:start --only functions
и перехожу к заданному URL-адресу http://localhost:5001/post-dach/us-central1/getNotifications
Все, что я получаю, это результат. Я использую Почтальон и делаю Post
запрос с
'Content-Type': 'application/json'
Тело
{
"data": {
"aString": "some string"
}
}
Ответ
{
"result": null
}
Также когда я пытаюсь что-то зарегистрировать в терминале, оно не появляется, и все, что я получаю, это большой журнал из firebase.
Есть идеи, что я здесь не так делаю?
Моя функция
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import { Notification, Request } from '../models'
const db = admin.firestore();
export const notificationsCall = functions.https.onCall((data, context) => {
const notificationsQuery = db.collection('notifications')
const notifications: Notification[] = [];
return notificationsQuery.get().then(snapshot => {
const requestsRef: FirebaseFirestore.DocumentReference[] = [];
const notIndexes: number[] = [];
snapshot.forEach((doc) => {
notifications.push(doc.data() as Notification);
});
notifications.forEach((notification, index) => {
if (notification.requestReference) {
requestsRef.push(notification.requestReference);
notIndexes.push(index);
}
});
return db.getAll(...requestsRef);
}).then((requests) => { // kthen requests
const packagesRef: FirebaseFirestore.DocumentReference[] = [];
requests.forEach((req, index) => {
const requestt = req.data() as Request
packagesRef.push((requestt).packageReference)
notifications[index].request = requestt
})
return db.getAll(...packagesRef)
}).then(packages => {
packages.forEach((pkg, index) => {
notifications[index].request.package = pkg;
})
return { notifications: notifications };
}).catch(err => { err })
});