【问题标题】:HTTP 404 Error setting hooking up Google's Cloud Run to Firebase Hosting将 Google 的 Cloud Run 连接到 Firebase 托管的 HTTP 404 错误设置
【发布时间】:2021-12-06 17:48:49
【问题描述】:

我一直在关注本指南 https://medium.com/firebase-developers/hosting-flask-servers-on-firebase-from-scratch-c97cfb204579,但我被 firebase 的 ./node_modules/.bin/firebase serve 命令困住了

我成功地能够使用 Cloud Run 部署项目并获得适用于该站点的服务 url,但是当我尝试在本地提供它时,它在运行到 localhost:5000 时在静态页面上产生此错误:

尝试处理代理重写时出现问题:查找 Cloud Run 服务的 URL 时出错:FirebaseError:HTTP 错误:404,项目中区域“us-central1”中类型“SERVICE”的资源“flask-fire” 'cjcflaskapp10192021' 不存在。

这是我的 firebase.json 文件。

{
  "hosting": {
    "public": "static",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [{
      "source": "**",
      "run": {
        "serviceId": "flask-fire"
      }
    }]
  }
}

【问题讨论】:

  • 您尝试从您的计算机调用 localhost:5000?但是你应该调用 Cloud Run 服务不是吗?

标签: python flask google-cloud-run


【解决方案1】:

article comments我发现几个用户也遇到了同样的错误,一个特别的评论是指Firebase Hosting和Cloud Run服务之间的区域不匹配:

看起来区域选择是重要的一步。因为在第一步中,我在区域 us-west-1 中部署了服务器端代码 ( app.py ),它运行良好。但是在设置了 firebase 部署设置后,它奇怪地在 us-central1 区域查找了我的 URL。 错误日志: 尝试处理代理重写时出现问题:查找 Cloud Run 服务的 URL 时出错:FirebaseError:HTTP 错误:404,项目“us-central1”区域中“SERVICE”类型的资源“flask-simple-pwa”烧瓶简单 pwa' 不存在。 当我检查 firebase 的文档时,在 Location us-west1 is nowhere to be seen 。 自您撰写本文以来,这可能已经发生了变化。这是您可以验证的吗?

official documentation 介绍了如何从 Cloud Run 提供动态内容以与 Firebase 托管一起使用,该内容更完整,并说明应在 firebase.json 上设置一个与您当前 Cloud Run 的区域相匹配的区域部署。如果未设置区域,FIrebase 托管将默认为 us-central1

"hosting": {
  // ...

  // Add the "rewrites" attribute within "hosting"
  "rewrites": [{
    "source": "/helloworld",
    "run": {
      "serviceId": "helloworld",  // "service name" (from when you deployed the container image)
      "region": "us-central1"     // optional (if omitted, default is us-central1)
    }
  }]
}

如果这与您的 Cloud Run 部署不匹配,则可能会导致此错误。有关 Firebase 支持的位置列表,您可以参考 this 页面。

【讨论】:

    猜你喜欢
    • 2020-10-26
    • 2020-03-02
    • 2019-04-02
    • 1970-01-01
    • 1970-01-01
    • 2019-09-10
    • 1970-01-01
    • 2019-10-10
    • 2021-09-06
    相关资源
    最近更新 更多