我使用Polymerfire的聚合物2.0网络应用程序的项目,并使用firebase deploy
发布到firebase托管
我有另一个项目,其云功能对数据库触发器起作用,并使用firebase deploy --only functions:updateOnChange
我的另一个项目是云功能,它是一个带有路由映射GET /fns/register
,POST /fns/register
和PUT /fns/register/confirm
的快速应用。我已使用firebase deploy --only functions:register
我已经创建了重写规则,将路由/fns/**
映射到firebase.json文件中我的第一个项目(聚合物1)中的注册云功能。我认为这是当前的firebase限制,我们无法管理多个项目的重写规则。
以下是第一个项目(聚合物项目)中的firebase.json
:
{
"database": {
"rules": "database.rules.json"
},
"hosting": {
"public": "build/default/public",
"rewrites": [
{
"source": "/fns/**",
"function": "fns"
},
{
"source": "**",
"destination": "/index.html"
}
]
}
}
现在我的/fns/register
请求被路由到我的register
云端功能,但我在应用中写的res.sendFile
无效。它总是说
TypeError: path must be absolute or specify root to res.sendFile
at ServerResponse.sendFile (/user_code/node_modules/express/lib/response.js:410:11)
at app.get (/user_code/index.js:28:13)
at Layer.handle [as handle_request] (/user_code/node_modules/express/lib/router/layer.js:95:5)
at next (/user_code/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/user_code/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/user_code/node_modules/express/lib/router/layer.js:95:5)
at /user_code/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/user_code/node_modules/express/lib/router/index.js:335:12)
at next (/user_code/node_modules/express/lib/router/index.js:275:10)
at expressInit (/user_code/node_modules/express/lib/middleware/init.js:40:5)
代码中的我的日志语句不起作用,即使我发送简单的res.send(JSON.stringify({ a: 1 }, null, 3));
,它仍会抛出相同的上述错误。
这意味着,我的代码没有被执行,或者我的库没有上传到我的云功能。我想了解云功能与应用程序的部署范围/体系结构/依赖关系。
在Google IO 2017中,重复的建议是为应用程序使用微服务开发风格,而不是单个整体。我在这里关注的是微服务式开发,但没有在哪里!
请在这里帮助我。
答案 0 :(得分:1)
我遇到的问题不是直接来自firebase或它的路由。问题在于我的快速应用程序配置。我修好了,一切都运行正常。
此外,我已经从多个项目创建了微服务(云功能),并且能够使用firebase deploy --only functions:fun1,fun2
独立部署它们,并且范围似乎工作得很好。我一直在不同的微服务中使用不同版本的js库,我现在没有遇到任何冲突!
虽然我不知道firebase部署策略的内部结构。我可以从我迄今为止的经验断言,微服务的每个部署都以某种方式沙箱化,以便其他微服务项目没有冲突!
唯一的问题是需要在一个项目中处理路由,这是可以理解的,因为如果支持多个项目支持重写规则,则维护多个路由规则和可能的冲突的复杂性。
知识渊博的人可能会纠正我的理解。