node.js - firebase node.js/express.js 添加多个firebase函数
问题描述
我正在尝试index.ts
按照此处的示例在文件中添加多个 Firebase 函数:如何构建 Cloud Functions for Firebase 以从多个文件部署多个函数?.
特别是,我有一个express.js
初始化的服务器routes.ts
:
const server = express();
server.get('/api', (req, res) => res.send('hello /api'))
export {server}
现在在 index.ts 中,我可以导入routes.ts
并附加一个用户身份验证侦听器,以便在创建新用户时触发,即:
import {server} from './routers'
exports.app = functions.https.onRequest(server);
exports.userEvents = functions.auth.user().onCreate(user => {
console.log("user created: ", user.email, user)
})
然而,据我所知exports.app
,它实际上是按预期工作的,并且exports.userEvents
似乎不会在创建新用户时触发。
==================================================== =======
编辑:
问题是我的firebase.json
函数是如何设置的,它目前只服务于app
以 开头的端点/api/**
,即:
{
"hosting": {
"public": "public",
// the problem is here: you're not connecting to multiple functions
"rewrites": [{
"source": "/api/**"
, "function": "app"
}],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
},
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
}
现在的问题是我如何告诉 firebase 从exports.userEvents
...提供功能
解决方案
问题是我试图模拟本地环境中的功能。我必须部署它们http
才能运行非功能。但是,文档底部描述了其他功能的本地模拟器:https ://firebase.google.com/docs/functions/beta-v1-diff ,这是新的。
推荐阅读
- python - 包含具有相同外键的相关对象的查询集
- angular - 为什么 getter 有时会在模板中触发?
- list - 使用 ansible 访问字典文件的 yaml 列表
- mysql - 从表 A 中选择,并将其设置在表 B 中不存在的值自定义 JPA 查询
- javascript - 为什么这个选择标签在反应中不能正常工作?
- android - 无法获取最后一个已知位置
- c# - 如何为 katana/owin 自托管设置默认静态控制器
- c++ - 使用 OpenCV 进行奇怪的 uint8_t 转换
- google-cloud-datastore - 带有嵌入式项目集合的谷歌数据存储查询
- android - MITMProxy:Android 上未捕获 TCP/UDP 和 WebSocket