javascript - 如何使用firebase函数从父文件夹中读取文件
问题描述
app.get('/sign-in', (req, res) =>{
res.writeHead(200);
res.end(fs.readFileSync('../html/Login.html'));
})
app.get('/sign-up', (req, res) =>{
console.log('connecting sign-up BABY');
res.writeHead(200);
res.end(fs.readFileSync('../html/Register.html'));
})
如您所见,我正在使用 fs.readFilesync 来调用 html 文件。这很奇怪,因为它通过使用在 localhost 上firebase serve
工作,但在部署后它在 firebase 服务器上不起作用。错误信息更令人困惑。它只说Error: could not handle the request
并且控制台显示
Function execution started
Function execution took 1559 ms, finished with status: 'connection error'
解决方案
当您部署 Cloud Functions 时,Firebase 会部署文件夹中的functions
文件。您的代码似乎正在尝试从不同的文件夹中读取文件。由于该文件夹尚未部署到 Cloud Functions,因此它失败了。
您从 Cloud Functions 代码中读取的任何内容都应位于该functions
文件夹中/下。您可能希望在部署之前将文件夹移动/复制到文件夹html
中。files
推荐阅读
- javascript - 导航栏没有按我想要的方式工作
- vue.js - 在模态Bootstrap Vue js中循环
- java - 如何为 Kafka 2.2 实现 FlinkKafkaProducer 序列化程序
- javascript - 如何摆脱几何?
- sql - 重用具有不同 WHERE 子句的子查询
- mysql - MYSQL - 如何检查一列是否有值或者它是否为空而另一列的值如 10
- powershell - Windows powershell 简化文件名
- ios - 是否有可能在 iOS 中的任何脚本代码的帮助下从同一代码创建具有不同捆绑 ID 的多个项目名称?
- c# - 使用 sql 批量插入将大 csv 文件保存到 azure 数据库的最快方法是什么?
- python - (42000、[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]s. (102) (SQLExecDirectW) 附近的语法不正确)