Firebase Cloud Function 编写与部署
1、设置和初始化 Firebase SDK for Cloud Functions
(1)、Cloud Functions 运行的是 Node v6.14.0,因此需要安装nodejs: https://nodejs.org/ (2)、安装CLI工具:
npm install -g firebase-tools
(3)、初始化配置,请执行以下操作:
运行 firebase login,通过浏览器登录并对 Firebase 工具进行身份验证。
转到 Firebase 项目目录。
运行 firebase init functions。该工具会为您提供使用 npm 安装依赖项的选项。如果要以其他方式管理依赖项,您可以放心地拒绝。
该工具支持两种语言:
JavaScript
TypeScript。 如需了解详情,请参阅使用 TypeScript 编写函数。
完成后本地文件目录看起来就像这样
myproject
+- .firebaserc # Hidden file that helps you quickly switch between
| # projects with `firebase use`
|
+- firebase.json # Describes properties for your project
|
+- functions/ # Directory containing all your functions code
|
+- .eslintrc.json # Optional file containing rules for JavaScript linting.
|
+- package.json # npm package file describing your Cloud Functions code
|
+- index.js # main source file for your Cloud Functions code
|
+- node_modules/ # directory where your dependencies (declared in
# package.json) are installed
2、修改函数
您的项目必须使用 Node require 语句导入 Cloud Functions 和 Admin SDK 模块。请将如下代码行添加到您的 index.js 文件中
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
添加函数
exports.addMessage = functions.https.onRequest((req, res) => {
const original = req.query.text; //接收函数传递的参数
return admin.database().ref('/messages').push({original: original}).then((snapshot) => {
return res.redirect(303, snapshot.ref.toString());
});
});
3、部署和执行 addMessage()
(1)在ssh终端运行以下命令部署您的函数
firebase deploy --only functions //部署index.js中的所以函数
如果只部署其中一个函数(加上函数名) firebase deploy --only functions:addMessage
4、访问函数
https://us-central1-MY_PROJECT.cloudfunctions.net/addMessage?text=uppercaseme

Firebase Cloud Function 编写与部署的更多相关文章
- Error: errCode: -404011 cloud function execution error | errMsg: clou……错误
在开通了云开发之后,无论点击小程序获取openid按钮报,Error: errCode: -404011 cloud function execution error | errMsg: clou…… ...
- [login] 调用失败 Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID , cloud function service error code -501000, error message Environment not found;
按照微信开放文档,创建完云开发项目,运行,点击获取openid,报如下错: [login] 调用失败 Error: errCode: -404011 cloud function execution ...
- Windows Azure NotificationHub+Firebase Cloud Message 实现消息推动(付源码)
前期项目一直用的是Windows azure NotificationHub+Google Cloud Message 实现消息推送, 但是GCM google已经不再推荐使用,慢慢就不再维护了, 现 ...
- Linux shell编写脚本部署pxe网络装机
Linux shell编写脚本部署pxe网络装机 人工安装配置,Linux PXE无人值守网络装机 https://www.cnblogs.com/yuzly/p/10582254.html 脚本实 ...
- [Firebase] Firebase Cloud Functions
Firebase cloud functions is similar to AWS lambda or serverless. You can deploy you code which wrote ...
- 微信小程序调用云函数出错 Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail cloud function service error code -501005, error message Environment not found;
错误异常: Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail cloud ...
- 超实用!!!使用IDEA插件Alibaba Cloud Toolkit工具一键部署本地应用到ECS服务器
最近看到阿里云发布了一款名为 Alibaba Cloud Toolkit 的插件,可以帮助开发者高效开发并部署适合在云端运行的应用,瞬间击中了我的小心脏,这个对于个人开发者来说超级棒啊,终于不需要再手 ...
- shell脚本编写-自动部署及监控
1.编写脚本自动部署反向代理.web.nfs: I.部署nginx反向代理两个web服务,调度算法使用加权轮询 II.所有web服务使用共享存储nfs,保证所有web都对其有读写权限,保证数据一致性: ...
- 编写、部署、应用JavaBean
编写javabean 编写javabean实质上就是编写一个java类.设计javabean类就是要设计这个javabean的属性和方法,类的方法的命名遵循以下规则: 1)如果成员变量的名字是xx ...
随机推荐
- pat1064. Complete Binary Search Tree (30)
1064. Complete Binary Search Tree (30) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...
- [luogu 3369]普通平衡树(fhq_treap)
题目描述 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作: 插入x数 删除x数(若有多个相同的数,因只删除一个) 查询x数的排名(排名定义为比当前数小的数的个数+1.若有多 ...
- ORA-29875 出现问题解决办法
出现问题:Underlying DBMS error [ORA-29875: 无法执行 ODCIINDEXINSERT 例行程序ORA-20085: Insert Spatial Reference ...
- SpringMVC09 Converter变流器、数据回显、异常测试
1.配置web.xml文件 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3// ...
- Spring整合Struts2 XML版
1.jar包 <!--spring配置--> <dependency> <groupId>org.springframework</groupId> & ...
- Spring scope 配置
Scope 描述的是 Spring 容器如何新建Bean的实例,Spring的Scope有以下几种,通过@Scope来注解实现: 1. Singleton: 一个Spring容器中只有一个Bean的实 ...
- Django的路由层和视图层
一丶Django 的路由层(URLconf) URL配置(URLconf)就像Django 所支撑网站的目录.它的本质是URL与要为该URL调用的视图函数之间的映射表:你就是以这种方式告诉Django ...
- ajax的jquery写法和原生写法
一.ajax的简介 Ajax被认为是(Asynchronous(异步) JavaScript And Xml的缩写).现在,允许浏览器与服务器通信而无须刷新当前页面的技术都被叫做Ajax. 同步是指: ...
- django Q条件
#q条件from django.db.models import Qq = Q(name__startswith="p") | Q(name__startswith="l ...
- Bugzilla-5.0.3 (OpenLogic CentOS 7.2)
平台: CentOS 类型: 虚拟机镜像 软件包: apache2.4.6 bugzilla5.0.3 mariadb5.5.47 perl5.16.3 apache bug tracking bug ...