我已将 next.js 应用部署到 Google Cloud,并且正在使用 Functions 和 Hosting。
我最近尝试将所有内容移至 northamerica-northeast1
区域。我重新部署了所有函数,将 .region("northamerica-northeast1")
放在所有函数的开头,如图 here。这成功地更新了我所有函数的位置。
不过,我也使用了一个函数来为我的 next.js 应用提供服务:
const server = functions.https
.onRequest((request, response) => {
return app.prepare().then(() => handle(request, response));
});
然后我将所有 URL 重新写入此函数:
"hosting": {
"target": "webapp",
"public": "public",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"function": "nextjs-server"
}
]
},
这都是 Google Cloud 上的标准 next.js,我已经这样做了 2 年多。但是,当我使用这个将函数移动到新区域时:
const server = functions
.region("northamerica-northeast1")
.https
.onRequest((request, response) => {
return app.prepare().then(() => handle(request, response));
});
看来重写不再有效。该函数已更新,但是当我访问该站点时,我收到了 404。然后,当我将该函数移回默认区域(通过删除 .region())时,它又可以正常工作了。
我尝试了 3 个当前的项目,同样的事情。
最后,我尝试创建一个全新的、全新的项目并部署到 northamerica-northeast
区域(和以前一样),并将其中包含区域代码的功能实时推送......所以我的项目从未托管在任何地方除了 northamerica-northeast1
并且它仍然失败。但是,通过删除该区域,重写再次开始正常工作,我可以看到该站点。即使网站的其余部分都在 northamerica-northeast1
区域中,并且只有这一服务器功能移到了默认区域。
我相信这是在谷歌云上重写的一个错误?或者是我遗漏了什么或某个地方的某个文档说该地区无法进行重写?
答案 0 :(得分:1)
如果您想同时使用 Hosting 和 Cloud Functions,函数位于 us-central1
。
Firebase 托管仅在 us-central1 中支持 Cloud Functions。
Serve dynamic content and host microservices with Cloud Functions