typescript - Lokal testning av Firebase Cloud Functions misslyckas
jag vill testa min enkla molnfunktion på min lokala dator, så att jag inte behöver distribuerar den varje gång jag ändrar koden.
Jag har redan loggat in på Firebase igen och jag använder nu Firebase-skalet för att kalla på funktionerna
Detta är min molnfunktionkod men jag kommer inte så långt att kunna köra den
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);
});
});
Varje gång jag använder firebase functions:shell och anropar: getPossibleFriend({"data": {"nickname": "någon sträng"},"context": {"asdf": "asdf"}})
Jag får:
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"
}
}