如何在 firebase 托管中使用已声明的 public 文件夹重写 base url?
How to use rewrite for base url with a declared public folder in firebase hosting?
我正在尝试配置一个 Web 应用程序以托管所有静态资源,例如 jpeg、png 等。但出于各种安全原因,我想将所有请求路由到云功能以监控流量。
除了家庭路线之外,我使用以下方法为所有路线实现了这一点:
"hosting": {
"public": "public", //without this everything goes through function, with it the base url is treated like a static get for index.html
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"function": "sendWebApp"
}
]
}
我面临的问题是家庭 route/base url 请求。它忽略了“myurl.com”的重写,但使用了“myurl.com/whatever-I-type-here”的重写。我怎样才能让它也路由到基本 url 的函数?
(为清楚起见。)
编辑:如何让 firebase 托管不将基础 url 视为对 index.html 的静态请求?
默认情况下,当向基础 URL 发出请求时,Firebase 托管始终会从声明的 public 文件夹发送 index.html。覆盖它的唯一方法是删除 index.html 或不在 firebase.json
的托管配置中包含“public”声明。
因为 static files ignore the rewrites configuration,您可以将重写简化为:
"hosting": {
// ... other props ...
// Serves the function for requests to files or directories that do not exist
"rewrites": [ {
"source": "**",
"function": "sendWebApp"
} ]
}
重要的是,如果您正在访问站点的目录,例如 /
或 /dashboard/
,这些目录中的 index.html
如果存在,将会被提供。这意味着在这些情况下永远不会检查您配置的重写规则。
我正在尝试配置一个 Web 应用程序以托管所有静态资源,例如 jpeg、png 等。但出于各种安全原因,我想将所有请求路由到云功能以监控流量。
除了家庭路线之外,我使用以下方法为所有路线实现了这一点:
"hosting": {
"public": "public", //without this everything goes through function, with it the base url is treated like a static get for index.html
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"function": "sendWebApp"
}
]
}
我面临的问题是家庭 route/base url 请求。它忽略了“myurl.com”的重写,但使用了“myurl.com/whatever-I-type-here”的重写。我怎样才能让它也路由到基本 url 的函数?
(为清楚起见。) 编辑:如何让 firebase 托管不将基础 url 视为对 index.html 的静态请求?
默认情况下,当向基础 URL 发出请求时,Firebase 托管始终会从声明的 public 文件夹发送 index.html。覆盖它的唯一方法是删除 index.html 或不在 firebase.json
的托管配置中包含“public”声明。
因为 static files ignore the rewrites configuration,您可以将重写简化为:
"hosting": {
// ... other props ...
// Serves the function for requests to files or directories that do not exist
"rewrites": [ {
"source": "**",
"function": "sendWebApp"
} ]
}
重要的是,如果您正在访问站点的目录,例如 /
或 /dashboard/
,这些目录中的 index.html
如果存在,将会被提供。这意味着在这些情况下永远不会检查您配置的重写规则。