带有 Firebase 托管的 Firebase 函数重定向到错误 URL

Firebase Function with Firebase Hosting redirects to wrong URL

我有一个连接到 Firebase 托管的自定义子域 - api.example.com

此外,我在 Firebase Functions 中有一个函数

exports.test = functions
    .region('europe-west3')
    .https.onRequest((request, response) => {
        const expiresIn = 60 * 60 * 24 * 5 * 1000;
        const origin = request.headers.origin;

        const options = { maxAge: expiresIn, httpOnly: true, secure: true, sameSite: 'strict',  };
        response.cookie('__session', "123456", options);
        response.set('Access-Control-Allow-Origin', origin);
        response.set('Access-Control-Allow-Credentials', true);
        response.end(JSON.stringify({ status: 'success' }));
})

我的 Firebase.json 看起来像下面这样

{
  "functions": {
    "source": "functions"
  },
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [{
        "source": "/test",
        "function": "test"
    }]
  }
}

现在,当我尝试向 https://api.example.com/test 发出 POST 请求时 我得到一个错误

Your client does not have permission to get URL /test/test from this server.

正如 URL 所说 /test/test/

我在这里做错了什么?有什么建议么?谢谢。

Firebase 托管不支持除 us-central1 以外的区域用于 Cloud Functions。见 documentation:

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

另请参阅 GitHub 上的此问题:https://github.com/firebase/firebase-tools/issues/842