【问题标题】:How to access firebase hosting file from firebase function如何从 firebase 功能访问 firebase 托管文件
【发布时间】:2018-03-04 18:13:30
【问题描述】:

我有一个简单的 firebase 函数,它必须发送一个文件以响应文件在 /app/one.html 中的请求

我的项目目录结构

blog
|____app
      |____index.html
      |____one.html
|____functions
      |____index.js

我必须访问 one.html 并从 senFile() 发送它

index.js

const functions = require('firebase-functions');
exports.blog = functions.https.onRequest((req, res) => {
    res.status(200).sendFile('app/one.html'); #here I need something to do
});

【问题讨论】:

  • 如果你想发送 one.html 替换 index.html
  • 好的,不管它是什么文件,都应该被访问。 @kgangadhar

标签: node.js firebase firebase-hosting


【解决方案1】:

据我所知,firebase deploy for functions 仅部署 functions 文件夹的内容。因此,如果您将应用程序文件夹移动/复制到函数文件夹内部,您就可以实现您想要做的事情。

blog
|____functions
      |____app
          |____index.html
          |____one.html
      |____index.js

正确更改路径后,您可以像快速应用程序一样发送文件。

res.sendFile(path.join(__dirname + 'app/one.html'));

【讨论】:

    猜你喜欢
    • 2018-04-08
    • 2017-11-03
    • 2020-04-12
    • 2017-08-14
    • 1970-01-01
    • 2020-06-13
    • 2018-11-12
    • 2018-08-09
    • 2018-10-31
    相关资源
    最近更新 更多