Search code examples
firebaseserver-side-renderingfirebase-hostingangular-universalgoogle-cloud-run

Firebase Hosting rewrite doesn't show SSR content on Google Cloud Run


In order to Server Side Render my project I have set up a docker container with Node.js. The container is registered at Google's Container Registry and connected to a service at Cloud Run. When I use the provided Service URL the site is SSR and everything looks perfectly fine.

To connect the project with firebase I wrote this redirect:

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

Unfortunately, when I look at the code now, it isn't rendered Serverside anymore.

Has someone encountered similar issues?

EDIT:

As Michael mentions the problem is the second index.html file. You can see that this is served. (I added a test comment to be sure)

enter image description here

So the solution is simply to remove your index.html file from the public directory. Thank you Michael for helping out!


Solution

  • (a guess as to what's happening)

    If you have an index.html in your dist/browser folder and visit the root path for your site (/), the static HTML will be served instead of calling the Cloud Run service.

    As you can see in the docs, "exact-match" static content has a higher priority than rewrites.

    To solve this, you would simply remove your index.html file from the public directory.