首页 > 解决方案 > 我无法从 Firebase 函数加载公用文件夹中的 html 文件

问题描述

我知道路径目录是正确的路径,只是我总是得到错误'Error: ENOENT: no such file or directory, stat '/public/resetp.html'

我的路径如下:

index.js: firebase/functions/index.js
reset password.html: firebase/public/resetp.html

当我在我的网站上的函数上访问此端点时,它会运行以下代码:

response.sendFile(path.join(__dirname, '/./public/resetp.html'));

我需要使用 sendFile() 函数,以便只呈现 html 文件而不更改 URL,因为在我尝试加载的 html 文件中,它获取 URL 的参数(如操作代码)和获取用户输入以重置用户密码。

谢谢,内森

标签: htmlfirebasegoogle-cloud-functionsfirebase-hosting

解决方案


您可以通过在public目录中创建目录来实现此目的functions

{
  "hosting": {"public": "functions/public"}
}

functions目录中的所有文件都使用 Cloud Functions 部署,并且没有可用的文件之外的文件。

警告:可用的文件将是部署 Cloud Functions 时公共目录中的任何文件。您可以确保托管和功能部署保持同步。


推荐阅读