云功能存储和部署目标 [英] Cloud function storage and deploy target

查看:42
本文介绍了云功能存储和部署目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Firebase上使用部署目标,除我的Cloud功能外,其他一切工作正常.

I'm using deploy targets on Firebase and everything is working fine except my Cloud functions.

  1. process.env.FIREBASE_CONFIG env变量的值不正确.属性"databaseURL"和"storageBucket"不是我已配置目标使用的属性
  2. 当我使用 admin.database()时,它没有使用我已经创建且想要使用的正确的RTDB
  3. functions.storage.object().onFinalize()没有监视"正确的存储桶
  1. The process.env.FIREBASE_CONFIG env variable doesn't have the right values. The properties "databaseURL" and "storageBucket" are not the one I've configured the target to use
  2. When I use admin.database() it doesn't use the right RTDB I've created and that I want to use
  3. functions.storage.object().onFinalize() doesn't "watch" the right bucket

我的 .firebaserc 文件

{
    "projects": {
        "default": "hatch-rpg",
        "dev": "hatch-rpg"
    },
    "targets": {
        "hatch-rpg": {
            "hosting": {
                "shadra": [
                    "shadra"
                ]
            },
            "database": {
                "shadra": [
                    "hatch-shadra-dev"
                ]
            },
            "storage": {
                "shadra": [
                    "hatch-shadra-dev"
                ]
            }
        }
    }
}

我的 firebase.json 文件

{
    "firestore": {
        "rules": "firestore.rules",
        "indexes": "firestore.indexes.json"
    },
    "database": [
        { "target": "shadra", "rules": "database.rules.json" }
    ],
    "functions": {
        "predeploy": [
            "npm --prefix \"$RESOURCE_DIR\" run lint",
            "npm --prefix \"$RESOURCE_DIR\" run build"
        ],
        "source": "functions"
    },
    "hosting": [
        {
            "target": "shadra",
            "public": "dist/shadra",
            "ignore": [
                "firebase.json",
                "**/.*",
                "**/node_modules/**"
            ],
            "rewrites": [
                {
                    "source": "**",
                    "destination": "/index.html"
                }
            ]
        }
    ],
    "storage": [
        { "target": "shadra", "rules": "storage.rules" }
    ]
}

我正在像这样初始化Firebase

I'm initializing Firebase like this

admin.initializeApp(functions.config().firebase);

我想念什么?

非常感谢

我试图通过执行 firebase函数来覆盖FIREBASE_CONFIG:config:set firebase.databaseURL ="hatch-shadra-dev.firebaseio.com" firebase.storageBucket ="hatch-shadra-dev" ,但它没有无效,因为无效的配置名称firebase.databaseURL,不能使用大写.然后尝试不使用大写并得到无法设置为保留的命名空间firebase 如何覆盖此FIREBASE_CONFIG?还是我不应该使用它手动初始化firebase?

I have tried to override FIREBASE_CONFIG by doing firebase functions:config:set firebase.databaseURL="hatch-shadra-dev.firebaseio.com" firebase.storageBucket="hatch-shadra-dev" but it didn't worked because Invalid config name firebase.databaseURL, cannot use upper case. then tried without uppercase and got Cannot set to reserved namespace firebase How can I override this FIREBASE_CONFIG ? or should I just not use it initialize manually firebase ?

推荐答案

好,这是我为解决此问题所做的事情.

Ok, here's what I did to fix this issue.

也许有更好的选择,或者我只是在这里滥用Firebase.无论如何,这是解决方案:

Maybe there's a better option or I'm just mis-using Firebase here. Anyway, heres' the solution:

首先,向项目添加一些配置

First, add some config to the project

firebase functions:config:set target.database="hatch-shadra-dev.firebaseio.com" target.bucket="hatch-shadra-dev"

然后通过admin.initializeApp()在Cloud函数中使用它

Then use it in the Cloud function with admin.initializeApp()

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';

const config = functions.config();
admin.initializeApp({
  ...config.firebase,
  storageBucket: config.target.bucket,
  databaseURL: `https://${config.target.database}`
});

这篇关于云功能存储和部署目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆