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 ...
随机推荐
- HDU - 5920 Ugly Problem 求解第一个小于n的回文数
http://acm.hdu.edu.cn/showproblem.php?pid=5920 http://www.cnblogs.com/xudong-bupt/p/4015226.html 把前半 ...
- malloc内存申请--释放-收缩
一.验证思路和代码 #include <stdio.h> #include <unistd.h> #include <malloc.h> #include < ...
- docker的卸载方法
卸载: 1.查询docker安装过的包: yum list installed | grep docker 2.删除安装包: yum remove docker-ce.x86_64 ddocker-c ...
- ACdream 1427—— Nice Sequence——————【线段树单点更新,区间查询】
Nice Sequence Time Limit: 4000/2000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Su ...
- Git常用操作命令收集
Git常用操作命令收集 1.进入本地仓库访问位置之后执行命令 1) 远程仓库相关命令 检出仓库:$ git clone git://github.com/jquery/jquery.git 查看远 ...
- javascript之常用正则表达式
一.校验数字的表达式 1 数字:^[0-9]*$ 2 n位的数字:^\d{n}$ 3 至少n位的数字:^\d{n,}$ 4 m-n位的数字:^\d{m,n}$ 5 零和非零开头的数字:^(0|[1-9 ...
- Windows 10 取消桌面右键“图像属性”、“图像选项”
Windows 10 取消桌面右键"图像属性"."图像选项" 桌面右键 说明:在windows 10中,桌面右键出现"图像属性"." ...
- fstab 解析
某些时候当Linux系统下划分了新的分区后,需要将这些分区设置为开机自动挂载,否则,Linux是无法使用新建的分区的. /etc/fstab 文件负责配置Linux开机时自动挂载的分区. Window ...
- Retrofit 2.0 轻松实现多文件/图片上传/Json字符串/表单
如果嫌麻烦直接可以用我封装好的库:Novate: https://github.com/Tamicer/Novate 通过对Retrofit2.0的前两篇的基础入门和案例实践,掌握了怎么样使用Retr ...
- 关于Mybatis的pagehelper使用遇到的坑
参考博客: https://blog.csdn.net/wzyxdwll/article/details/66473466 下面给出pagehelp使用的配置, 在springmvc中的配置: 下面是 ...