多个域通过Firebase托管和云功能提供独立的内容? [英] Multiple domains serving independent content with Firebase hosting and Cloud Functions?

查看:84
本文介绍了多个域通过Firebase托管和云功能提供独立的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计和构建一个Web应用程序,用户可以在其中上传静态HTML模板文件.我的系统将解析其模板并创建用于各自目的的JavaScript代码.

I'm designing and building a web app in which users will upload a static HTML template file. My system will parse their template and create JavaScript code for their individual purpose.

我希望每次使用都拥有自己的名称空间,因此理想情况下,端点应该看起来像这样

I want each use to have their own namespace, so ideally the endpoints would look something like this

user1.domain.com/index.html
user1.domain.com/code.js

user2.domain.com
user2.domain.com/code.js

...

不可能以编程方式将静态文件写入Firebase托管,因此我设想有一个Cloud Function可以检查HTTP主机并提供​​适当的文件.用户1的index.html模板文件将以类似的方式存储在Firebase存储中,而用户2则存储在其自己的子空间中.

It's not possible to programmatically write static files to Firebase hosting, so I envisaged having a Cloud Function that would inspect the HTTP host and serve up the appropriate files. User 1's index.html template file would be stored in Firebase Storage in its own sub-space and User 2's in a similar manner.

最终目标是将www.userone.comwww.usertwo.com(我的客户选择的域)分别映射到user1.domain.comuser2.domain.com,但是我可以使用外部CDN代理请求来实现.

The end goal is to have www.userone.com and www.usertwo.com (my customers chosen domains) mapped to user1.domain.com and user2.domain.com respectively, but I could achieve this using an external CDN proxying requests.

为了使上述解决方案起作用,我需要在每个用户参与我的应用程序时(使用Firebase控制面板)将域手动添加到我的Firebase项目中.我预计总共会有200位客户.

In order for the above solution to work I would need to manually add domains to my Firebase project (using the Firebase control panel) as each user participates in my app. I expecting around 200 customers total.

我可以使用staging.domain.com/user-{n},然后只需要为Firebase项目配置一个域.但是,这将迫使用户不得不在模板中使用指向其内容的相对链接.而且,他们将有权访问其他用户的内容,即user-1/index.html可以访问../user-2/code.js,这不是安全隐患,但会引起用户更多易出错的习惯.

I could use staging.domain.com/user-{n} and then I would only have to configure a single domain for my Firebase project. However, this would force users to have to use relative links to their content within their template. Also, they would have access to other users content i.e. user-1/index.html could access ../user-2/code.js which isn't a security risk but invites more error prone idiocies from users.

是否可以配置主机以将*.domain.com映射到单个Cloud Function,或者至少手动映射user1.domain.comuser2...?

Is there a way to configure the hosting to map *.domain.com to a single Cloud Function, or at least user1.domain.com, user2... manually?

如果没有,是否可以使用Google Cloud Infrastructure实现上述方案? (我担心的是,可以附加到单个项目的域数量没有记录的限制.)

If not, can the above scenario be achieved using Google Cloud Infrastructure? (My concern is there is an undocumented limit to the number of domains that can be attached to a single project.)

推荐答案

是否可以通过一种方式将托管配置为将* .domain.com映射到单个Cloud Function,或者至少手动映射到user1.domain.com,user2 ...?

Is there a way to configure the hosting to map *.domain.com to a single Cloud Function, or at least user1.domain.com, user2... manually?

您可以将多个域映射到Firebase Hosting项目.但是每个域都将提供完全相同的内容.

You can map multiple domains to a Firebase Hosting project. But each domain will serve the exact same content.

无法将Firebase Hosting配置为为映射到同一项目的不同域提供不同的内容.

There is no way to configure Firebase Hosting to serve different content for different domains mapped to the same project.

另请参阅:

  • Firebase hosting with multiple directories at multiple domains
  • Firebase hosting: Serve different pages from different custom domains
  • Multiple domains with the same application running firebase as the backend
  • How do I make a custom subdomain on Firebase?

这篇关于多个域通过Firebase托管和云功能提供独立的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆