Cloud Functions 和 Firebase Functions 有什么区别? [英] What is the difference between Cloud Functions and Firebase Functions?

查看:24
本文介绍了Cloud Functions 和 Firebase Functions 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

云函数Firebase 函数(或Firebase 的云函数") 看起来都一样.请描述每个的用例.

Cloud Functions and Firebase Functions (or "Cloud Functions for Firebase") both look the same. Please describe the use case of each.

两者都使用 HTTP 函数.

Both use HTTP functions.

云函数中:

exports.helloHttp = function helloHttp (req, res) {
  res.send(`Hello ${req.body.name || 'World'}!`);
};

Firebase 函数中:

exports.helloWorld = functions.https.onRequest((request, response) => {
  response.send("Hello from Firebase!");
});

这些有什么区别?

推荐答案

没有名为 Firebase Functions 的产品.

There is no product called Firebase Functions.

有三个不同的东西:

  1. Google Cloud Functions,允许您在 Google 的基础架构中运行代码片段以响应事件.
  2. Cloud Functions for Firebase,根据 Firebase 中的事件(例如作为数据库或文件写入、用户创建等)
  3. Firebase SDK for Cloud Functions,其中包括一个库(混淆地称为 firebase-您在 Functions 代码中用于访问 Firebase 数据(例如写入数据库的数据的快照)的函数)
  1. Google Cloud Functions, which allow you to run snippets of code in Google's infrastructure in response to events.
  2. Cloud Functions for Firebase, which triggers Google Cloud Functions based on events in Firebase (such as database or file writes, user creation, etc)
  3. Firebase SDK for Cloud Functions, which includes a library (confusingly called firebase-functions) that you use in your Functions code to access Firebase data (such as the snapshot of the data that was written to the database)

因此,Firebase 围绕 Google Cloud Functions 提供了一个(相对较薄的)包装器,以使后者的产品更易于使用并将其与 Firebase 集成.从这个意义上说,它类似于 Firebase 如何将 Google Cloud Storage 集成到Cloud Storage for Firebase"(以前称为 Firebase Storage)中.

So Firebase provides a (relatively thin) wrapper around Google Cloud Functions, to make the latter product easier to use and integrate it with Firebase. In that senses it is similar to how Firebase integrates Google Cloud Storage into "Cloud Storage for Firebase" (formerly known as Firebase Storage).

如果您在没有 Firebase 的情况下使用 Google Cloud Platform,那么您应该使用普通的 Google Cloud Functions.如果您使用 Firebase,或者您是对 Cloud Functions 感兴趣的移动开发者,您应该使用 Cloud Functions用于 Firebase.

If you're using Google Cloud Platform without Firebase, then you should use plain Google Cloud Functions. If you're on Firebase or if you're a mobile developer interested in Cloud Functions, you should use Cloud Functions for Firebase.

这篇关于Cloud Functions 和 Firebase Functions 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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