Firebase托管重写不会重定向到Google Cloud Run

Dre*_*ton 6 firebase firebase-hosting google-cloud-run

我正在使用Firebase托管设置重定向(重写),以便可以调用从google cloud运行在此处运行的api 。

我尝试过更改重写字符串"/api/**"(应将所有内容捕获到page.com/api/**并将其发送给函数)。删除了index.html并交换为"**"捕获所有路径,包括索引。到目前为止没有任何工作。

我的托管firebase.json是这样设置的,这有什么问题吗?

{
  "hosting": {
    "public": "dist/public",
    "ignore": ["firebase.json", "**.*", "**/node_modules/**"],
    "rewrites": [
      {
        "source": "**",
        "run": {
          "serviceId": "next-js-base-api",
          "region": "us-central1"
        }
      }
    ]
  }
}

Run Code Online (Sandbox Code Playgroud)

我还尝试了正常重定向到另一个页面,这不起作用,是什么决定了firebase.json设置何时开始传播和起作用?

更新资料

我尝试运行托管模拟器,并进行了修改后的重写"source": "/api/**",结果如下。导航到/ api返回非崩溃(不重定向),浏览器中的输出cannot GET /api导航到api / wkapi(由api端点捕获的子目录)unexpected error在浏览器中返回,

Error: Unable to find a matching rewriter for {"source":"/api/**","run":{"serviceId":"next-js-base-api","region":"us-central1"}}
Run Code Online (Sandbox Code Playgroud)

在控制台中。

Arw*_*win 5

确保通过运行以下命令更新到最新版本的 Firebase CLI:

npm install -g firebase-tools@latest
Run Code Online (Sandbox Code Playgroud)

这将使您能够按照您尝试的方式重写云运行实例。

  • 我通过以下方式使其工作:1)将源设置为“**”2)从公共目录中删除index.html (3认同)