标签: firebase-cli

在本地调试 Firebase 函数 (node.js)

看下面我的代码非常简单......它监听实时数据库中数据库字段的变化。

const functions = require("firebase-functions");
var admin = require("firebase-admin");

exports.onActiveUpdate = functions.database
  .ref("/profiles/users/{userId}/active")
  .onUpdate((change, context) => {
      //code here
      
    return true;
  });
Run Code Online (Sandbox Code Playgroud)

我尝试使用以下命令在本地调试代码

firebase serve --only functions
firebase serve
firebase emulators:start
Run Code Online (Sandbox Code Playgroud)

我总是收到同样的消息...

+  functions: Emulator started at http://localhost:5001
i  functions: Watching "C:\code\rn\xs\fb_functions\functions" for Cloud Functions...
i  functions[onActiveUpdate]: function ignored because the database emulator does not exist or is not running.
+  All emulators started, it is now safe to connect.
Run Code Online (Sandbox Code Playgroud)

但是当我转到 localhost:5001 时......我看到的只是一个{"status":"alive"}顶部带有 的空白页面。

这是正确的行为吗?谢谢

debugging firebase-realtime-database google-cloud-functions firebase-cli

4
推荐指数
1
解决办法
6215
查看次数

Firebase Firestore 模拟器如何工作?

到目前为止,我一直在使用 Firebase Hosting 和 Functions 模拟器。但现在我正在编写一个基于 Firestore 触发器运行的函数,因此我正在研究 Firestore 模拟器进行开发。

但它是如何运作的呢?它完全模仿 Firestore 吗?我能否读取保存在服务器上的当前 Firestore 数据?如果我更新、创建或删除更改文档,我是否也会在真实数据中真正更改它们?

我将运行它:

firebase emulators:start --only hosting,functions,firestore

node.js firebase google-cloud-functions google-cloud-firestore firebase-cli

4
推荐指数
1
解决办法
966
查看次数

您正在现有的Firebase项目目录中进行初始化

我如何在cli中更改firebase项目?

当我运行firebase init时,它说:

Before we get started, keep in mind:

  * You are initializing in an existing Firebase project directory

? Are you ready to proceed? (Y/n)
Run Code Online (Sandbox Code Playgroud)

它从不询问我需要上传哪个项目。请指导我如何链接我的其他项目?

firebase firebase-hosting firebase-cli

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

Firebase托管部署到其他站点

如何部署到同一项目中定义的其他Firebase托管站点。我创建了多个托管“网站”的Firebase。命令

firebase deploy
Run Code Online (Sandbox Code Playgroud)

但是总是部署到第一个。如何指定将静态文件部署到另一个“站点”(和域)。

谢谢

firebase firebase-hosting firebase-cli

3
推荐指数
2
解决办法
1904
查看次数

在终端中部署一个函数成功但没有出现在控制台中

我使用带有sudo firebase deploy.

我得到回应:

=== Deploying to 'first-60012'...

i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> functions@ lint /Users/name/Desktop/ME/Projects/first/functions
> eslint .

?  functions: Finished running predeploy script.
i  functions: ensuring necessary APIs are enabled...
?  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...

?  Deploy complete!
Run Code Online (Sandbox Code Playgroud)

转到 firebase.com 中的控制台,在功能中显示“等待您的第一次部署”。

试了3次,什么都没出现。

firebase google-cloud-functions firebase-cli

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

Firebase Function not giving Function URL

I am creating my first firebase function app and I was going/following through this tutorial/repo

So what I did was in my main file Index.js (inside functions folder)

const app = express();
const functions = require("firebase-functions");

const authRoutes = require("./src/routes/auth.js");
const meetupRoutes = require("./src/routes/meetup.js");
const eventbriteRoutes = require("./src/routes/eventbrite.js");
const nonMiddleWareRoutes = require("./src/routes/nonMiddleware.js");

app.use("/", nonMiddleWareRoutes);
app.use("/auth", authRoutes);
app.use("/meetup", meetupRoutes);
app.use("/eventbrite", eventbriteRoutes);

const api = functions.https.onRequest(app);

module.exports = {
  api
};
Run Code Online (Sandbox Code Playgroud)

now moving back to the root folder we have firebase.json which …

firebase google-cloud-functions firebase-cli

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

使用 node --inspect 将 Firebase 模拟函数附加到浏览器 DevTools

我正在尝试node --inspect将我的index.jsFirebase 函数附加到 chrome devtools,以获得比终端日志提供的更丰富的调试体验。

到目前为止,我没有成功。这是我尝试过的:

  1. 只需运行其中一个firebase servefirebase emulators:start(但 Chrome devtools 似乎没有检测到这些)

  2. 运行node --inspect反对functions/index.js,供应其上localhost:9229,而不是在仿真器的情况下,这是我需要的其他服务(hostingfirestore)。

  3. 阅读节点文档和这篇 SO 帖子:Can't debug node.js using Chrome DevTools

我不确定是否

  • (a) 我遗漏了一些基本的东西(很有可能),
  • (b) 无法将功能模拟器附加到浏览器开发工具,或
  • (c) 有可能,但被窃听或未实施(在这种情况下,我将用 开启一个错误/功能请求firebase-tools)。

任何方向表示赞赏。

node.js google-chrome-devtools firebase firebase-cli

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

如何从 Firebase 配置中获取measurementId?

一起玩谷歌Analytics(分析)对火力地堡的基于Web的项目,我们需要为使用的火力地堡保留网址或复制/更新火力地堡配置对象作为文档状态这里

不过,我正在使用以下命令打印该配置信息:firebase setup:web.

问题是它没有打印measurementId字段。

我现在该怎么办?

firebase google-analytics-firebase firebase-cli

3
推荐指数
2
解决办法
5994
查看次数

如何更改节点版本?“您请求的“节点”版本“8”与您的全球版本“10”不匹配

当我在终端 firebase 模拟器中运行时会发生这种情况:start

波纹管所有输出

i  emulators: Starting emulators: functions, hosting
?  hub: emulator hub started at ht tp://localhost:4400
?  Your requested "node" version "8" doesn't match your global version "10"
?  functions: functions emulator started at ht tp://localhost:5001
i  hosting: Serving hosting files from: dist/spa-mat
?  hosting: Local server: ht tp://localhost:5000
?  hosting: hosting emulator started at http://localhost:5000
i  functions: Watching "/var/w ww/html/teachers/agnos2108-app.teachersnow-6391de281bf3/functions" for Cloud Functions...
?  functions[sendEmailLogger]: http function initialized (ht tp://localhost:5001/teachernow-7082b/us-central1/sendEmailLogger).
?  functions[sendMail]: http function initialized (ht tp://localhost:5001/teachernow-7082b/us-central1/sendMail). …
Run Code Online (Sandbox Code Playgroud)

node.js firebase firebase-cli

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

firebase deploy 找不到与模式“'src/**/*'”匹配的文件

我试图在 firebase 上部署我的第一个云函数,但问题是它总是说有问题并且没有文件与模式匹配我不知道为什么即使 index.ts 是它应该是错误代码的地方是

=== Deploying to 'mscmu-aeab1'...

i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> functions@ lint C:\Users\fahmi\msc_mu\cloud_functions\functions
> eslint 'src/**/*'


Oops! Something went wrong! :(

ESLint: 7.9.0

No files matching the pattern "'src/**/*'" were found.
Please check for typing mistakes in the pattern.

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! functions@ lint: `eslint 'src/**/*'`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the functions@ lint script.
npm ERR! …
Run Code Online (Sandbox Code Playgroud)

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

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