标签: google-cloud-functions

如何在PC上本地测试Firebase的云功能

今天,Firebase发布了全新的Cloud Products for Firebase产品,我刚创建了一个hello world功能,并将其部署在我现有的firebase项目中.

看起来它捆绑所有依赖项并将其上传到firebase就像aws lambda函数一样.但即使在代码的微小变化上也需要太多时间才能完成,并且还需要良好的互联网连接.如果由于某种原因您处于脱机状态,那么在您可以在本地计算机上执行和测试该功能的方法之前,您所处的代码就处于黑暗状态.

有没有办法在本地测试Firebase的云功能?

function node.js firebase google-cloud-functions firebase-cloud-functions

33
推荐指数
3
解决办法
1万
查看次数

解析错误:按照 ​​Firebase Cloud Functions 初始化说明后无法读取文件“\tsconfig.json”eslint

问题

在我的 TypeScript 项目在 VSCode 中初始化后,使用 firebase 工具按照官方文档编写 Firebase Cloud Functions,文件的第一行index.ts显示错误:

Parsing error: Cannot read file '\tsconfig.json' eslint [1,1] 在此输入图像描述

并且.eslintrc.js显示错误:

File is a CommonJS module; it may be converted to an ES6 module.ts(80001) 在此输入图像描述

由于所有文件都是自动生成的,这些错误完全令人惊讶,我想摆脱它们。

版本

作为记录,以下是安装的版本:

npm      --version 8.1.3
tsc      --version 4.4.4
node     --version 17.0.1
firebase --version 9.22.0
Run Code Online (Sandbox Code Playgroud)

安装流程

这些是我在 VSCode 的 powershell 中使用的命令以及一些信息/警告:

>npm install -g firebase-tools
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated uuid@3.4.0: Please upgrade …
Run Code Online (Sandbox Code Playgroud)

firebase typescript eslint google-cloud-functions

32
推荐指数
2
解决办法
2万
查看次数

Firebase的云功能因超出内存限制而被杀死

转换相对较小的图像(2mb)时,我不断从Cloud Functions for Firebase中得到零星的错误.如果成功,该功能只需要大约2000ms或更短的时间来完成,根据Image Magick文档,我不应该看到任何问题.

我尝试增加命令的缓冲区大小,这是Firebase中不允许的,我试图找到替代方案,.spawn()因为它可能会因为垃圾和速度慢而过载.什么都行不通.

memory-management firebase google-cloud-functions

31
推荐指数
8
解决办法
1万
查看次数

通过 /__/quitquitquit 函数代码库请求的 Firebase 函数关闭无法成功分析。它可能有语法或运行时错误

我正在尝试部署我的功能。我添加了第二个并重构了第一个,现在我无法部署。我尝试绕过 CI/CD 手动部署,但仍然出现错误。这是一个 2.0 函数,我确实运行了 tsc。自从我上次部署以来,我确实重新安装了 firebase-tools 包。除了我提到的以外,与它工作时没有什么不同。

\n

以下是 的输出firebase deploy --only functions

\n
i  deploying functions\nRunning command: npm --prefix "$RESOURCE_DIR" run lint\n\n> lint\n> eslint --ext .js,.ts .\n\nRunning command: npm --prefix "$RESOURCE_DIR" run build\n\n> build\n> tsc\n\n\xe2\x9c\x94  functions: Finished running predeploy script.\ni  functions: preparing codebase default for deployment\ni  functions: ensuring required API cloudfunctions.googleapis.com is enabled...\ni  functions: ensuring required API cloudbuild.googleapis.com is enabled...\ni  artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...\n\xe2\x9c\x94  functions: required API cloudbuild.googleapis.com is enabled\n\xe2\x9c\x94  functions: required API …
Run Code Online (Sandbox Code Playgroud)

node.js firebase google-cloud-functions

31
推荐指数
3
解决办法
1万
查看次数

从Cloud Functions for Firebase中的数据库触发器获取用户标识?

在下面的示例中,有没有办法获取写入/ messages/{pushId}/original的用户的uid?

exports.makeUppercase = functions.database.ref('/messages/{pushId}/original')
.onWrite(event => {
  // Grab the current value of what was written to the Realtime Database.
  const original = event.data.val();
  console.log('Uppercasing', event.params.pushId, original);
  const uppercase = original.toUpperCase();
  // You must return a Promise when performing asynchronous tasks inside a Functions such as
  // writing to the Firebase Realtime Database.
  // Setting an "uppercase" sibling in the Realtime Database returns a Promise.
  return event.data.ref.parent.child('uppercase').set(uppercase);
});
Run Code Online (Sandbox Code Playgroud)

javascript firebase firebase-realtime-database google-cloud-functions

30
推荐指数
2
解决办法
8706
查看次数

如何从云功能连接Google Cloud SQL?

我正在尝试使用Cloud Functions for Firebase来构建一个与Google Cloud SQL(PostgreSQL)实例对话的API.

我正在使用HTTP(S)触发器.

当我列出桌面的IP地址时,我可以使用本地计算机上的函数node.js代码连接到Cloud SQL.但是当我部署时,我无法连接,我无法弄清楚Firebase功能服务器的HOST IP地址到白名单.

您如何通过Cloud Functions for Firebase与Google Cloud SQL对话?

谢谢!

// Code Sample, of what's working on Localhost.
var functions = require('firebase-functions');

var pg = require('pg');
var pgConfig = {
  user: functions.config().pg.user,
  database: functions.config().pg.database,
  password: functions.config().pg.password,
  host: functions.config().pg.host
}

exports.helloSql = functions.https.onRequest((request, response) => {
  console.log('connecting...');
  try {
    client.connect(function(err) {
      if (err) throw err;

      console.log('connection success');
      console.log('querying...');

      client.query('SELECT * FROM guestbook;', function(err, result){
        if (err) throw err;

        console.log('querying success.');
        console.log('Results: ', …
Run Code Online (Sandbox Code Playgroud)

javascript google-cloud-sql firebase google-cloud-platform google-cloud-functions

30
推荐指数
5
解决办法
1万
查看次数

错误:HTTP错误400,请求有错误.Firebase Firestore云功能

当我运行命令firebase deploy时,我收到此错误:

我部署功能

我的职责是:确保启用必要的API ...

i runtimeconfig:确保启用必要的API ...

✔timetimeconfig:启用所有必需的API

✔功能:启用所有必需的API

我的功能:准备功能目录上传...

我的功能:用于上传的打包功能(4.04 KB)

✔功能:功能文件夹上传成功

我开始发布过程(可能需要几分钟)...

我的功能:创建函数跟随者通知......

⚠功能:无法创建函数followerNotification

⚠功能:HTTP错误:400,请求有错误

⚠功能:1个功能未能部署.

功能部署有错误.要继续部署其他功能(例如>数据库),请运行:firebase deploy --except functions

错误:功能未正确部署.

遇到麻烦?尝试firebase deploy --help

其他一切都没有问题.只有当我尝试用Firebase Firestore制作东西时.

firebase google-cloud-functions google-cloud-firestore

30
推荐指数
5
解决办法
8294
查看次数

Firebase 存储工件巨大且不断增加

我刚刚注意到我的应用程序的存储空间在过去几周内几乎达到了 5GB 的免费使用限制。更详细地检查后,似乎这是由“工件”存储桶引起的。

我看到了这个 SO question,它说“工件”存储桶与 Node 10 环境有关。

我确实在一个月前搬到了 Node 10,但在发现日志不再在 Firestore 功能控制台中构建后,几天后我又恢复到 Node 8,从那时起只使用 Node 8。

但是我可以看到“工件”存储每周增加约 800Mb,这让我至少担心(请查看下面的屏幕截图)

我认为这与 Firestore 功能部署有关(或不是?),但这真的是预期的吗?我可以安全地清理这些工件吗?

对我来说,它在短短几周内急剧增加,这对我来说很奇怪,而以前我使用函数几年,从来没有遇到过这样的问题。

感谢有关如何在这种情况下安全处理存储大小并将其消耗保持在最低限度的任何建议。

我也在使用pubsub.schedule函数以防它在这里很重要。

在此处输入图片说明 在此处输入图片说明 在此处输入图片说明

我还注意到“神器”的带宽出乎意料地飙升,我猜这也有成本影响,我很感激任何有关尽量减少此类峰值的可能方法的意见(22.5GB 中约有 22GB 来自“神器”存储桶):

在此处输入图片说明

在此处输入图片说明

firebase google-cloud-functions firebase-storage

30
推荐指数
1
解决办法
3162
查看次数

Firebase的云功能 - 验证电子邮件的操作

我试图创建一个云功能触发器,它将在验证电子邮件后执行.

Cloud Functions示例中,我只能找到关于onCreate和的触发器的示例onDelete.

文档中,我发现了一些关于创建自定义操作处理程序的内容,但我实际上并不想要替换默认情况下的标准电子邮件验证对话框,我只想在验证电子邮件后更改"用户"的属性.

有没有人有这方面的经验,这甚至可能吗?或者我是创建自定义验证视图/对话框网页的唯一选择?

firebase firebase-authentication google-cloud-functions

29
推荐指数
2
解决办法
2474
查看次数

功能被杀死.错误:超出配额

我在Spark Plan上使用Firebase的云功能.

我使用cronJob每2分钟调用一次函数.

我最近得到了这个错误:

功能被杀死.错误:超出配额

尝试部署时,我收到类似的错误:

部署错误:功能加载错误:错误:超出配额

我知道火花计划有一个配额,但我的统计数据如下:

118处决

207总调用

火花计划表示你获得125,000 /月免费调用是否有执行限制?我尝试部署一个新功能,但我得到相同的错误.

我超过了什么配额?

firebase google-cloud-functions

27
推荐指数
1
解决办法
1万
查看次数