【问题标题】:How can I serve static web site from firebase hosting through node expressjs?如何通过 node expressjs 从 firebase 托管服务静态网站?
【发布时间】:2019-10-01 06:48:36
【问题描述】:

重复使用来自 How can I serve static web site from s3 through node expressjs? 的问题,但在 Firebase 上下文中使用。

目前我使用 app.use(express.static('public')) 和我的文件位于我的节点 js express 应用程序的公用文件夹中,并且运行良好。但是,我想将这些文件(index.html 等)存储在我们的 Firebase 托管中(以便多个应用程序可以使用该网站)。我试过了

app.get('/', function(req, res) {
    res.sendfile('*-firebaseapp.com/index.html'); 
 });

是否有任何特定方法可以将托管在 Firebase 中的静态网站呈现给 Express 应用程序?

感谢您的帮助!

【问题讨论】:

    标签: node.js firebase express firebase-hosting


    【解决方案1】:

    res.sendFile() method 将其path 参数定义为:

    path 必须是文件的绝对路径。

    您的 Express 函数在 Cloud Functions 中运行,它是 Google 基础架构上的无服务器容器。 Firebase 托管在不同的基础架构中运行,大部分服务发生在边缘缓存上。

    Cloud Functions 代码无权访问托管基础架构的文件系统。

    因此,如果您想从 Firebase Hosting 提供文件,则必须通过 HTTP(S) 请求它们,这与任何客户端都必须做的类似。或者,您可以考虑将 HTML 文件部署到 Cloud Functions 容器中,方法是将它们放入您的 index.js/index.ts 文件所在的文件夹中。

    【讨论】:

      猜你喜欢
      • 2017-03-08
      • 1970-01-01
      • 1970-01-01
      • 2016-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-14
      • 2017-01-12
      相关资源
      最近更新 更多