我有一个项目,其中设置了多个 Firebase 托管项目(用于登台和生产),当我根据 Firebase 文档添加重写here 时,函数 /bigben 的重写在 https://customdomain.com/bigben 不起作用(部署到生产环境和模拟器中)
firebase.json
{
"hosting": [
{
"target": "production",
"public": "build",
"rewrites": [
{
"source": "/bigben",
"function": "bigben"
},
{
"source": "**",
"destination": "/index.html"
},
{
"source": "!/@(js|css|svg|jpg|png|gif|ico|json|html)/**",
"destination": "/index.html"
}
]
// ...
},
{
"target": "staging",
"public": "build",
"rewrites": [
{
"source": "/bigben",
"function": "bigben"
},
{
"source": "**",
"destination": "/index.html"
},
{
"source": "!/@(js|css|svg|jpg|png|gif|ico|json|html)/**",
"destination": "/index.html"
}
]
// ...
}
]
}
如何设置 /bigben 以使用此自定义域(已在 Firebase 中配置用于托管/前端 create-react-app?我已经看到从构建文件夹中删除 index.html,但不是这样CRA 需要吗?
答案 0 :(得分:1)
我知道文档说您的 source
应该看起来像这样,一条简单的路径,但它似乎也对我不起作用。为 bigben 更改您的 source
:
"source": "/bigben",
为此:
"source": "/bigben/**",
之后它应该正确地进行重写。
编辑:
此外,您的重写是无序的,因此您的所有源文件都被重写为 index.html。以下是我建议的更改:
{
"hosting": [
{
"target": "production",
"public": "build",
"rewrites": [
{
"source": "/bigben/**",
"function": "bigben"
},
{
"source": "!**/*.*",
"destination": "/index.html"
}
]
// ...
},
{
"target": "staging",
"public": "build",
"rewrites": [
{
"source": "/bigben/**",
"function": "bigben"
},
{
"source": "!**/*.*",
"destination": "/index.html"
}
]
// ...
}
]
}