我有云功能
const app = express()
app.get('/ping', (req, res) => {
res.send('pong');
})
exports.api = functions.https.onRequest(app)
它工作正常
https://...cloudfunctions.net/api/ping
乒乓球
然后我添加以下配置
{
"hosting": {
"public": "public",
"rewrites": [ {
"source": "/api/**", "function": "api"
} ]
}
}
并尝试从应用程序 url 调用它,但它失败了。
https://...firebaseapp.com/api/ping
404
如果我像这样使用重写对我的函数的所有调用
{
"hosting": {
"public": "public",
"rewrites": [ {
"source": "**", "function": "api"
} ]
}
}
然后它起作用了
https://...firebaseapp.com/ping
乒乓球
我在这里遗漏了什么还是不支持这种情况?
有一篇关于此的博客文章,它在重写中使用和分段:
https://firebase.googleblog.com/2017/06/serving-dynamic-content-with-cloud.html
您需要将 /api 添加到快速路由的开头。 前缀不是
当 URL 发送到云函数时被切断。
2017 年 7 月 9 日星期日晚上 11:27,roosi [email protected]写道:
我有云功能
const app = express()
app.get('/ping', (req, res) => {
res.send('乒乓');
})export.api = functions.https.onRequest(app)
它工作正常
https://...cloudfunctions.net/api/ping
乒乓球然后我添加以下配置
{
“主持”:{
"公开": "公开",
“重写”:[ {
"source": "/api/**", "function": "api"
]]
}
}并尝试从应用程序 url 调用它,但它失败了。
https://...firebaseapp.com/api/ping
404如果我像这样使用重写对我的函数的所有调用
{
“主持”:{
"公开": "公开",
“重写”:[ {
“来源”:“**”,“功能”:“api”
]]
}
}然后它起作用了
https://...firebaseapp.com/ping
乒乓球我在这里遗漏了什么还是不支持这种情况?
有一篇关于此的博客文章,它在重写中使用和分段:
https://firebase.googleblog.com/2017/06/serving-dynamic-content-with-cloud.html
http://网址—
您收到此消息是因为您订阅了此线程。
直接回复本邮件,在GitHub上查看
https://github.com/firebase/firebase-tools/issues/392 ,或静音
线
https://github.com/notifications/unsubscribe-auth/AAAD_updmJ5mvK9NFrx5v-a0lQckEhaHks5sMcRogaJpZM4OSaDu
.
@roosi我上周也遇到了这个问题。 这很烦人,但对于这样的场景,我能想到的最佳解决方案是创建一个main
函数,该函数托管所有其他函数并重写所有对它的托管调用。 例如,这使您能够调用https://...firebaseapp.com/api/ping
。
有关更多详细信息,请参阅我的回答:
https://stackoverflow.com/a/45224176/1309346
最有用的评论
您需要将 /api 添加到快速路由的开头。 前缀不是
当 URL 发送到云函数时被切断。
2017 年 7 月 9 日星期日晚上 11:27,roosi [email protected]写道: