为 Firebase 托管代理外部 API?

问题描述 投票:0回答:1

我们创建了静态单页 WEB 应用程序,该应用程序使用外部 API 进行身份验证和数据。

我们设置了以

/api
为前缀的专用URL空间来解决反向代理的跨域限制。代理在本地设置上可以与 Ngnix、Apache 配合使用,但我在 Firebase Hosting 中找不到代理支持:https://firebase.google.com/docs/hosting/url-redirects-rewrites

有一个功能可以让节点运行时每次调用最多 1 分钟。不能用来实现反向代理吗?

更新 我们以 Heroku 产品结束。它通过 WEB 服务器(特定云提供商的内部细节)托管我们的静态 JS/CSS 资源,并且同一 WEB 服务器是用户通过定义的扩展点代理 API 调用,映射到 URL 根,如

/api

这种方式编写的 JS 应用程序可以在没有 schema / host / port 的情况下向 URL 发出 API 调用,无论您是在

localhost
(开发)还是在云环境(产品)中运行它都没有关系!

firebase google-cloud-functions firebase-hosting
1个回答
0
投票

有一种很好的方法可以让 Firebase Hosting 作为特定功能的代理: https://firebase.google.com/docs/hosting/full-config#rewrite-functions

这样,您就可以将特定路线直接定向到您的某个功能:

"hosting": {
  // ...

  // Directs all requests from the page `/bigben` to execute the `bigben` function
  "rewrites": [ {
    "source": "/bigben",
    "function": {
      "functionId": "bigben",
      "region": "us-central1"  // optional (see note below)
      "pinTag": true           // optional (see note below)
    }
  } ]
}
© www.soinside.com 2019 - 2024. All rights reserved.