Can not see the Firebase function deployed

后端 未结 15 1143
失恋的感觉
失恋的感觉 2021-02-02 08:23

I followed the following steps:

  1. The Firebase CLI (Command Line Interface) requires Node.js and npm, which you can install by following the instructions on https

15条回答
  •  我在风中等你
    2021-02-02 09:00

    For Cloud Functions, it is required to add your function to the special exports object (it is a Node's way of making the function accessible outside of the current file) Make sure to have index.js in your functions directory:

    Example of a function:

    // Import the Firebase SDK for Google Cloud Functions.
    const functions = require('firebase-functions');
    // Import and initialize the Firebase Admin SDK.
    const admin = require('firebase-admin');
    admin.initializeApp();
    
    
    
    // Your function declaration. Example of a fired function when a user is created in Auth feature.
    exports.myFunction = functions.auth.user().onCreate(async (user) => {
    // ... your code here.
    });
    

    Then for deployment follow these steps:

    • First, if not done, make sure to have firebase-tools installed: $ npm install -g firebase-tools
    • And initialised: $ firebase init

    • For full deployment: $ firebase deploy

    • OR for functions deployment $ firebase deploy --only functions
    • OR to deploy specific functions $ firebase deploy --only functions:function1,functions:function2

    A good read with a very useful example: https://codelabs.developers.google.com/codelabs/firebase-cloud-functions/#7

提交回复
热议问题