Ner*_*gen 5 proxy reverse-proxy firebase firebase-hosting google-cloud-functions
这就是我目前拥有的
domain.com -> website A with its own firebase host (domain.firebase.com)
me.domain.com -> website B with its own firebase host (domain-me.firebase.com)
Run Code Online (Sandbox Code Playgroud)
这并不难设置,只需将多个子域重定向到不同的 Firebase 主机即可。现在,我想要的是反向代理接受请求,并可以选择将流量路由到各种服务器,同时将客户端 URL 仅保留在domain.com主域上。我不确定这对于 Firebase是否可行,因为有大量的 NGINX 实现示例,但基本上,我想要这个:
domain.com/ -> website A with its own firebase host (domain.firebase.com)
domain.com/me -> website B with its own firebase host (domain-me.firebase.com)
Run Code Online (Sandbox Code Playgroud)
Firebase 具有非常复杂的重定向选项,但重定向也会覆盖客户端 URL。因此,通过重定向,客户端将看到domain-me.firebase.com而不是domain.com/me,这不是我想要的。
据我所知,我可以使用 Firebase Cloud 功能作为中间件,并让它根据需要为任一站点提供服务。然而,这会带来大量延迟,因为云功能和 Firebase 托管网站都有冷启动时的预热时间。
不给我完整而详细的答案也没关系,我真的只是想知道这是否可以开始,以及在哪里可以找到相关资源。谢谢!
回答我自己的问题并以 Doug 使用 Cloud Run 的答案为基础。有一种快速、轻松的方法可以使用 2 个应用程序设置类似反向代理的实现。去做这个:
1) 构建两个应用程序并将它们放在单独的文件夹中,例如文件夹 A 和文件夹 B。您只需要应用程序的构建文件夹,不需要源代码。
2) 在文件夹 A 和 B 的根目录下创建一个新的 Express 应用程序。
3) 让 Express 使用 app.get 管理路由并使用 res.sendFile 返回文件。
4) 按照此处的 Google 教程对整个 Express 应用程序进行容器化,您可以忽略示例应用程序,因为您的新 Express 应用程序就是应用程序。
5) 作为新服务上传到Cloud Run。请记住,虽然 Google 没有指定,但您需要授予用户上传到存储桶的权限。您将需要该命令,
如果您有多个项目gsutil iam ch user:[user]:objectViewer gs://us.artifacts.[project-name].appspot.com
,请确保使用命令切换到当前项目gcloud config set project [project-name]。
6) 使用 Google 域映射映射到您的根域,因此domain.com.
您必须使用域映射,因为 Cloud Run 使用的 URL 是短暂的……因为它是无服务器的。
你的文件夹结构应该是这样的
my-awesome-project
index.js <- Express app and Docker entry point
/package.json <- for your Express app
/A
/B
/Dockerfile
/node_modules
Run Code Online (Sandbox Code Playgroud)
示例路由器是
app.get('/me/*', (req,res) =>{
res.sendFile(path.join(__dirname+'/B/index.html'));
});
app.get('/*', (req,res) =>{
res.sendFile(path.join(__dirname+'/A/index.html'));
});
Run Code Online (Sandbox Code Playgroud)
在子域上设置应用程序的工作方式几乎相同。使用步骤 4 将每个单独的应用程序容器化,然后使用 Google 域映射单独映射每个域。
| 归档时间: |
|
| 查看次数: |
4721 次 |
| 最近记录: |