【问题标题】:Firebase Function with Firebase Hosting redirects to wrong URL带有 Firebase 托管的 Firebase 功能重定向到错误的 URL
【发布时间】:2021-08-24 15:45:31
【问题描述】:

我有一个连接到 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 请求时 我收到一个错误

您的客户端无权从此服务器获取 URL /test/test。

这是有道理的,因为 URL 上写着/test/test/

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

【问题讨论】:

    标签: javascript firebase cookies google-cloud-functions firebase-hosting


    【解决方案1】:

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

    重要提示:Firebase 托管仅在 us-central1 中支持 Cloud Functions。

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

    【讨论】:

      猜你喜欢
      • 2018-04-11
      • 2020-10-14
      • 2020-05-14
      • 2018-11-12
      • 1970-01-01
      • 2017-08-14
      • 1970-01-01
      • 2018-10-31
      • 2018-07-10
      相关资源
      最近更新 更多