Firebase Cloud Functions的本地测试失败

时间:2019-05-20 19:22:11

标签: typescript firebase google-cloud-functions firebase-cli

我想在本地计算机上测试我的简单云功能,因此我不必每次更改代码时都部署它。

我已经重新登录到Firebase,现在正在使用Firebase Shell调用函数

这是我的云函数代码,但到目前为止我还没有执行它

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并调用: getPossibleFriend({“ data”:{“ nickname”:“某字符串”},“ 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"
  }
}

0 个答案:

没有答案