我有一个简单的 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
});
最佳答案
据我所知,函数的 firebase deploy
仅部署函数文件夹的内容。因此,如果您将应用程序文件夹移动/复制到函数文件夹内部,您就可以实现您想要做的事情。
blog
|____functions
|____app
|____index.html
|____one.html
|____index.js
正确更改路径后,您可以像快速应用程序一样发送文件。
res.sendFile(path.join(__dirname + 'app/one.html'));
关于node.js - 如何从 firebase 函数访问 firebase 托管文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46377020/