代码之家  ›  专栏  ›  技术社区  ›  Renaud Tarnec

为云函数指定区域时出现异常“firebase.functions()接受…无参数…”

  •  2
  • Renaud Tarnec  · 技术社区  · 6 年前

    documentation 为了从网页调用位于 us-central1

    更准确地说,在网页上 var functions = firebase.functions('europe-west1'); 但是我得到了以下错误,并且没有从调用中得到结果:

    uncaught exception: functions: Firebase: firebase.functions() takes either no argument or a Firebase App instance. (app/invalid-app-argument).
    

    云函数

    const functions = require('firebase-functions');
    
    exports.getName = functions
      .region('europe-west1')
      .https.onCall((data, context) => {
        return { name: 'MyName' };
      });
    

    网页

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    
        <script src="https://www.gstatic.com/firebasejs/5.3.1/firebase-app.js"></script>
        <script src="https://www.gstatic.com/firebasejs/5.3.1/firebase-functions.js"></script>
    
    </head>
    
    <body>
        <script>
            // Initialize Firebase
            var config = {
                apiKey: "xxxxxxxxxx",
                authDomain: "xxxxxxxxxx",
                databaseURL: "xxxxxxxxxx",
                projectId: "xxxxxxxxxx",
                storageBucket: "xxxxxxxxxx",
                messagingSenderId: "xxxxxxxxxx",
            };
            firebase.initializeApp(config);   
    
            var functions = firebase.functions('europe-west1');
    
            var getName = functions.httpsCallable('getName');
            getName().then(function (result) {
                console.log((result.data));
            }).catch(function (error) {
                // Getting the Error details.
                var code = error.code;
                var message = error.message;
                var details = error.details;
            });
        </script>
    
    </body>
    </html>
    

    美国中部1 区域(呼叫 firebase.functions() 没有争论)它工作正常。

    美国中部1 版本)

    const functions = require('firebase-functions');
    
    exports.getName = functions  
      .https.onCall((data, context) => {
        return { name: 'MyName' };
      });
    

    美国中部1 版本)

    <!DOCTYPE html>
    <html lang="en">
    .....
    
    <body>
        <script>
            // Initialize Firebase
            var config = {
                 .....
            };
            firebase.initializeApp(config);
    
            var functions = firebase.functions();
    
            ...    
    
      </script>
    
    </body>
    </html>
    

    firebase-functions , firebase-admin firebase-tools .

    1 回复  |  直到 6 年前
        1
  •  4
  •   Giorgos Kartalis    6 年前

    经过反复试验,我发现你必须这样做:

    var config = {
                apiKey: "xxxxxxxxxx",
                authDomain: "xxxxxxxxxx",
                databaseURL: "xxxxxxxxxx",
                projectId: "xxxxxxxxxx",
                storageBucket: "xxxxxxxxxx",
                messagingSenderId: "xxxxxxxxxx",
            };
    var fireApp = firebase.initializeApp(config);
    var functions = fireApp.functions('europe-west1');
    
        2
  •  0
  •   GorvGoyl    5 年前

    var functions = firebase.app().functions('europe-west1');
    

    如文件所述 https://firebase.google.com/docs/functions/locations