为 Firebase 托管代理外部 API?

gav*_*koa 11 firebase firebase-hosting google-cloud-functions

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

我们设置了专用的 URL 空间前缀/api来解决反向代理的跨域限制。代理在本地设置中与 Ngnix、Apache 一起工作正常,但我在 Firebase 托管中找不到代理支持:https ://firebase.google.com/docs/hosting/url-redirects-rewrites

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

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

通过这种方式编写 JS 应用程序以向 URL 发出 API 调用,而无需架构/主机/端口,无论您是在localhost(开发)还是在云环境(产品)中运行它都没有关系!

Ida*_*lan 1

有一种很好的方法可以让 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)
    }
  } ]
}
Run Code Online (Sandbox Code Playgroud)