Firebase托管重写未在Google Cloud Run上显示SSR内容

时间:2020-06-11 11:54:31

标签: firebase server-side-rendering firebase-hosting angular-universal google-cloud-run

为了服务器端渲染我的项目,我已经用Node.js设置了一个Docker容器。 该容器已在Google的容器注册表中注册,并已连接到Cloud Run的服务。当我使用提供的服务URL时,该站点是SSR,一切看起来都很好。

要将项目与firebase连接,我编写了此重定向:

"hosting": {
"public": "dist/browser",
"ignore": [
  "firebase.json",
  "**/.*",
  "**/node_modules/**"
],
"rewrites": [
  {
    "source": "**",
    "run": {
      "serviceId": "nest-server-ssr",
      "region": "europe-west1"
    }
  }
]
},

不幸的是,当我现在查看代码时,它不再呈现在Serverside上。

有人遇到过类似的问题吗?

编辑:

正如迈克尔提到的,问题是第二个index.html文件。您可以看到已送达。 (我确定添加了测试评论)

enter image description here

因此解决方案只是从公共目录中删除index.html文件。谢谢迈克尔的帮助!

2 个答案:

答案 0 :(得分:1)

(对正在发生的事情的猜测)

如果您的index.html文件夹中有一个dist/browser,并访问了您网站的根路径(/),则将提供静态HTML,而不是调用Cloud Run服务。

您可以看到in the docs,“完全匹配”静态内容的优先级比重写的优先级高。

要解决此问题,只需从公共目录中删除index.html文件即可。

答案 1 :(得分:0)

你只需要将'index.html'添加到忽略列表中,这样它就不会被部署。

"hosting": {
"public": "dist/browser",
"ignore": [
  "index.html",
  "firebase.json",
  "**/.*",
  "**/node_modules/**"
],
"rewrites": [
  {
    "source": "**",
    "run": {
      "serviceId": "nest-server-ssr",
      "region": "europe-west1"
    }
  }
]
},