Vin*_*nny 5 firebase firebase-hosting
我在Firebase Hosting上看到意外的行为(至少按照我的说法),并带有斜杠。我希望Firebase可以在URL后面加上斜杠(托管目录中存在的实际文件除外)。为此,我设置trailingSlash到true在firebase.json。
结果是:
example.com redirect to example.com/index.html/
example.com/js/script.js redirect to example.com/js/script.js/
example.com/images/image.png redirect to example.com/images/image.png/
Run Code Online (Sandbox Code Playgroud)
预期的行为将是:
example.com redirect to example.com/
example.com/js/script.js served as it is without any redirect
example.com/images/image.png served as it is without any redirect
Run Code Online (Sandbox Code Playgroud)
在实际文件URL的末尾加上斜杠使浏览器/服务器认为script.js是目录而不是文件,并导致404。在根目录中添加index.html根本不是很优雅。
希望cleanUrls做我设置的伎俩cleanUrls,以true沿trailingSlash,并立即在网站进入无限重定向循环和加载失败。如何阻止Firebase在实际js或图像资产的根和尾部添加“ index.html”?
编辑:
按照弗兰克的要求,这是我正在使用的firebase.json:
{
"firebase" : "example",
"public" : "public",
"cleanUrls" : false,
"trailingSlash" : true,
"ignore" : [ "firebase.json", "**/.*", "**/node_modules/**" ],
"rewrites": [{
"source" : "**",
"destination" : "/index.html"
}],
"headers": [{
"source" : "**/*.@(eot|otf|ttf|ttc|woff|font.css)",
"headers" : [{
"key" : "Access-Control-Allow-Origin",
"value" : "*"
}]
}, {
"source" : "**/*.@(jpg|jpeg|gif|png)",
"headers" : [{
"key" : "Cache-Control",
"value" : "max-age=600"
}]
}, {
"source" : "**/*.@(html|js)",
"headers" : [{
"key" : "Cache-Control",
"value" : "max-age=300"
}]
}]
}
Run Code Online (Sandbox Code Playgroud)
PS:我已经尝试将trailingSlash和都设置cleanUrls为true,也尝试分别设置这些true/false。
小智 0
至于你的问题,如果你想调用“rewrites”命令,服务器可以在你的根目录下找不到任何index.html时执行“rewirtes”命令。
解决方案一:只需将index.html 放在“public”文件夹下的根目录中即可。我切换到您的公用文件夹并部署您的服务器。
解决方案二:将index.html放在某个文件夹下,您可以随意命名该文件夹。然后使用JSON格式:"rewrites": [{ "source" : "**", "destination" : "/folderName/index.html" }],但是你不能将任何index.html放在你的根文件夹下。
解决方案三:创建根文件夹,将 JS/CSS/IMG/ 文件夹和 index.html 放在根文件夹下。然后像这样部署服务器 JSON 文件。
{
"firebase": "you app name",
"public": ".",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1295 次 |
| 最近记录: |