0
votes

Full repo: https://github.com/jmsherry/firebase-full

firebase.json

{
  "hosting": {
    "predeploy": [
      "npm --prefix webapp run build"
    ],
    "public": "webapp/build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "/server-time",
        "function": "serverTime"
      },
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  },
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  }
}

I'm trying to my functions to work with hosting. The function is available (url: https://europe-west2-full-firebase-efc5a.cloudfunctions.net/serverTime) but The re-write for the server-time function works locally but when running on firebase hosting it 404s and redirects to the homepage (url: https://full-firebase-efc5a.firebaseapp.com/server-time)

It's like it's not being sent through to the function on firebase's end!

Can anyone shed any light?

1

1 Answers

2
votes

It looks like you deployed your function to region europe-west2. Unfortunately, that won't work at all with Firebase Hosting in production, since it only supports us-central1 for Cloud Functions. From the note in documentation:

Important: Firebase Hosting supports Cloud Functions in us-central1 only.

Consider instead using Cloud Run. It's more work, but you will be able to deploy to any supported region and it will work with Firebase Hosting.