英文:
Is it possible to use Firebase to direct requests to a Cloud Run container which is in another project
问题
在官方的 Firebase 文档上,看起来很容易看到我们可以通过代理将请求直接发送到我们的 Cloud Run 服务。
https://firebase.google.com/docs/hosting/full-config#rewrite-cloud-run-container
文档中说,如果你添加了你的 Cloud Run 服务的 serviceId,就可以实现:
"hosting": {
// ...
// 将所有来自页面 `/helloworld` 的请求定向到触发和运行 `helloworld` 容器
"rewrites": [ {
"source": "/helloworld",
"run": {
"serviceId": "helloworld", // 服务名称(从容器镜像部署时获取)
"region": "us-central1" // 可选(如果省略,默认为 us-central1)
}
} ]
}
然而,这并不解决我遇到的问题,因为我有不同的项目,所以无法直接提供容器镜像/服务名称。它们位于同一个帐户但不同的项目中。
我尝试直接指定目标:
"rewrites": [
{
"source": "/api/**",
"destination": "MY-CLOUD-RUN-APP-URL>/api/**"
},
{
"source": "**",
"destination": "/index.html"
}
]
然而,这并没有解决我的问题。
英文:
So on the official firebase documentation it looks pretty straightforward to see that we can direct requests to our Cloud Run via proxy.
https://firebase.google.com/docs/hosting/full-config#rewrite-cloud-run-container
So its says if you add your cloud run's serviceId it will be done:
"hosting": {
// ...
// Directs all requests from the page `/helloworld` to trigger and run a `helloworld` container
"rewrites": [ {
"source": "/helloworld",
"run": {
"serviceId": "helloworld", // "service name" (from when you deployed the container image)
"region": "us-central1" // optional (if omitted, default is us-central1)
}
} ]
}
However this does not cover my problem where you have different projects so you cannot directly give the container image/ service name. They are on the same account but in different projects.
I tried giving the direct destination:
"rewrites": [
{
"source": "/api/**",
"destination": "MY-CLOUD-RUN-APP-URL>/api/**"
},
{
"source": "**",
"destination": "/index.html"
}
However this didnt solve my problem.
答案1
得分: 0
这是不可能的。配置的Cloud Run实例必须与Firebase Hosting位于同一个项目中。
您可以可能设置一个Cloud Run容器来转发/代理HTTP请求到另一个位于另一个项目中的可以公开访问的Cloud Run实例(或者任何其他HTTP服务)。
英文:
This is not possible. The configured Cloud Run instances must be in the same project as Firebase Hosting.
You could possibly set up a Cloud Run container to forward/proxy HTTP requests to another publicly accessible Cloud Run instance in another project (or any other HTTP service for that matter).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论