我正在尝试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
...提供功能