尽管重写,firebase 托管仍未传递给 firebase 函数

firebase hosting not passing to firebase function despite re-write

完整回购: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"
  }
}

我正在尝试让我的函数与托管一起工作。函数可用 (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)

它好像没有被发送到 firebase 端的函数!

任何人都可以解释一下吗?

您似乎已将函数部署到区域 europe-west2。不幸的是,这对生产环境中的 Firebase 托管根本不起作用,因为它只支持云功能的 us-central1。来自 documentation 中的注释:

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

考虑改用 Cloud Run。这需要更多工作,但您将能够部署到任何受支持的区域,并且它可以与 Firebase 托管一起使用。