Firebase 托管:是否可以重写 URL 并将部分路径传递给 Cloud 运行?
Firebase Hosting: is it possible to rewrite a URL and pass part of the path to Cloud Run?
我想在 Cloud 运行 上使用 Firebase 托管在 /api
前缀上前置一个 API。因此 /api/something
的传入请求由 API /something
处理程序处理。看起来很简单,但我想不通,所以我想知道是否可以使用 Firebase 托管。
我尝试的第一件事是:
"rewrites": [
{
"source": "/api",
"run": {
"serviceId": "my-api",
"region": "us-central1"
}
}
]
这正确地将 /api
请求路由到服务根目录 /
,但调用 /api/something
仅需 404 秒。
第二次尝试使用 "source": "/api/**"
或 "regex": "/api(/.*)?",
。这正确地接收了 /api/something
之类的请求,但将其路由到 API root /
而不是 /something
.
理想情况下,我希望它去除 /api
前缀,或者允许我在路由 url 上使用提取的正则表达式组。
谢谢。
Ideally, I would like it to strip the /api prefix, or allow me to use the extracted regex group on the routed url.
那是不可能的。请求的完整 URI 将始终被保存并转发到 Cloud 运行。您在 Cloud 运行 端的代码应该能够处理发送到 Firebase 托管的完整路径。如果你想去除任何路径前缀,它必须在部署到云的代码中 运行.
我想在 Cloud 运行 上使用 Firebase 托管在 /api
前缀上前置一个 API。因此 /api/something
的传入请求由 API /something
处理程序处理。看起来很简单,但我想不通,所以我想知道是否可以使用 Firebase 托管。
我尝试的第一件事是:
"rewrites": [
{
"source": "/api",
"run": {
"serviceId": "my-api",
"region": "us-central1"
}
}
]
这正确地将 /api
请求路由到服务根目录 /
,但调用 /api/something
仅需 404 秒。
第二次尝试使用 "source": "/api/**"
或 "regex": "/api(/.*)?",
。这正确地接收了 /api/something
之类的请求,但将其路由到 API root /
而不是 /something
.
理想情况下,我希望它去除 /api
前缀,或者允许我在路由 url 上使用提取的正则表达式组。
谢谢。
Ideally, I would like it to strip the /api prefix, or allow me to use the extracted regex group on the routed url.
那是不可能的。请求的完整 URI 将始终被保存并转发到 Cloud 运行。您在 Cloud 运行 端的代码应该能够处理发送到 Firebase 托管的完整路径。如果你想去除任何路径前缀,它必须在部署到云的代码中 运行.