【发布时间】:2019-07-14 06:06:21
【问题描述】:
我有一个 Firebase 托管的单页应用。
我还有 3 个 Firebase 功能(联系人、计划、功能),应用程序和外部来源提出请求。
我的应用有一个自定义域,我想通过它访问我的功能。
这是我当前的firebase.json 配置
{
"hosting": {
"public": "www",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
因此,目前所有流量都流向我的应用程序,并且路由是通过我的 SPA 处理的。目前必须通过cloudfunctions.net URL 访问我的功能,这并不理想。
如何向此配置添加 URL 重写条目,以便通过我的自定义域访问我的函数并且我的单页应用程序处理其余路由?
我为features 端点尝试了以下方法:
"rewrites": [
{
"source": "/features/**",
"function": "features"
},
{
"source": "!/features/**",
"destination": "/index.html"
}
]
在我的函数index.js 我有:
...
exports.plans = functions.https.onRequest(plansApi);
exports.features = functions.https.onRequest(featuresApi);
exports.contact = functions.https.onRequest(contactApi);
但我收到404 Cannot GET /features/123 作为回复?
【问题讨论】:
标签: firebase google-cloud-functions single-page-application firebase-hosting