简体   繁体   English

我无法从我的 Firebase 函数加载公共文件夹中的 html 文件

[英]I can't load a html file in public folder from my Firebase function

I know the path directory is the right path, it's just that I always get the error 'Error: ENOENT: no such file or directory, stat '/public/resetp.html'我知道路径目录是正确的路径,只是我总是收到错误'Error: ENOENT: no such file or directory, stat '/public/resetp.html'

My paths are as follows:我的路径如下:

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

When I go to this endpoint on my function on my website it runs this code:当我在我网站上的函数上访问此端点时,它会运行以下代码:

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

I need to use the sendFile() function so that I can just render the html file and not change the URL since in the html file that I'm trying to load, it gets the parameters of the URL (like the action code) and gets the users input to reset the users password.我需要使用 sendFile() 函数,以便我可以只呈现 html 文件而不更改 URL,因为在我尝试加载的 html 文件中,它获取 URL 的参数(如操作代码)和获取用户输入以重置用户密码。

Thanks, Nathan谢谢,内森

You can achieve this by making your public directory inside your functions directory:您可以通过将public目录放在functions目录中来实现此目的:

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

All of the files in your functions directory are deployed with Cloud Functions, and no files outside of it are available. functions目录中的所有文件都使用 Cloud Functions 部署,并且没有可用的文件。

Warning: The files that will be available will be whatever files are in the public directory at the time you deploy Cloud Functions .警告:可用的文件将是您部署 Cloud Functions 时公共目录中的任何文件。 It is up to you to make sure Hosting and functions deploys are kept in sync.确保托管和功能部署保持同步取决于您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM