Я хочу протестировать свою простую облачную функцию на моем локальном компьютере, поэтому мне не нужно развертывать ее каждый раз, когда я меняю код.
Я уже повторно подключился к firebase и теперь использую оболочку Firebase длявызовите функции
Это мой код облачной функции, но я так далеко не могу его выполнить
export const getPossibleFriend = functions.region('europe-west1').https.onCall((data, context) => {
console.log(data);
const json = JSON.parse(data);
console.log(data);
console.log(json);
console.log("OAHOIODHSDHHID")
let test:string;
const parentRef = admin.database().ref("users");
return parentRef.once('value').then(snap => {
snap.forEach(function(child) {
if(child.child("nickname").val() === json["nickname"]){
console.log(child.val());
test = child.val();
}
});
}).catch(reason => {
console.log(reason);
}).then(() => {console.log(test);return test}).catch(reason => {
console.log(reason);
});
});
Каждый раз, когда я использую функции firebase: shell и call: getPossibleFriend ({"data": {"псевдоним": "некоторая строка"}, "context": {"asdf": "asdf"}})
Я получаю:
firebase > i Your code has been provided a "firebase-admin" instance. [object Object] Unhandled error SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at exports.getPossibleFriend.functions.region.https.onCall (/Users/skyy/Documents/GitHub/Waste-Less-Life/firebasetypescript/functions/lib/index.js:451:23)
at Object.<anonymous> (/Users/skyy/Documents/GitHub/Waste-Less-Life/firebasetypescript/functions/node_modules/firebase-functions/lib/providers/https.js:330:32)
at Generator.next (<anonymous>)
at /Users/skyy/Documents/GitHub/Waste-Less-Life/firebasetypescript/functions/node_modules/firebase-functions/lib/providers/https.js:28:71
at new Promise (<anonymous>)
at __awaiter (/Users/skyy/Documents/GitHub/Waste-Less-Life/firebasetypescript/functions/node_modules/firebase-functions/lib/providers/https.js:24:12)
at func (/Users/skyy/Documents/GitHub/Waste-Less-Life/firebasetypescript/functions/node_modules/firebase-functions/lib/providers/https.js:294:32)
at corsHandler (/Users/skyy/Documents/GitHub/Waste-Less-Life/firebasetypescript/functions/node_modules/firebase-functions/lib/providers/https.js:350:44)
at cors (/Users/skyy/Documents/GitHub/Waste-
Less->Lifefirebasetypescript/functions/node_modules/cors/lib/index.js:188:7)
RESPONSE RECEIVED FROM FUNCTION: 500, {
"error": {
"status": "INTERNAL",
"message": "INTERNAL"
}
}