Firebase主机路由重写(异常路径)



我正在尝试创建一个firebase路由规则,该规则将把特定子目录下的任何请求重新路由到服务器上的一个特定文件。

如果我有一个正常的文件路径(带有扩展名(,这是有效的,但如果我从初始请求中删除了扩展名,这似乎就不起作用了。

有人知道这种"重写"逻辑是如何工作的吗?有没有办法以这种方式利用它?

(或者我只是做错了,因为我不清楚为什么第一条规则也不起作用(

使用此规则集:

"rewrites": [
{
"source": "/access-token/somefolder/else.html",
"destination": "/access-token/2.json"
},
{
"regex": "^/access-token/[\d]+$",
"destination": "/access-token/2.json"
},
{
"regex": "^/access-token/[\d]+\.json$",
"destination": "/access-token/1.json"
},
{
"source": "**",
"destination": "/index.html"
}
]

测试结果:

request : https://[root]//access-token/somefolder/else.html   <-- this path does not exist, i was only using this as a test
expected: routes to 'destination'
actual  : routes to root (probably hitting final rule?)

request : https://[root]/access-token/12
expected: routes to 'destination'
actual  : routes to "404 not found"

request : https://[root]/access-token/12.json
expected: routes to 'destination'
actual  : re-routes as intended

对于第一个问题,由于重定向比重写具有更高的优先级,因此在到达重写引擎时,.html可能已经从传入URL中剥离。

{
"source": "/access-token/somefolder/else",
"destination": "/access-token/2.json"
}

对于以下项目,不要转义字符,并且IIRC也不需要锚。

{
"regex": "/access-token/d+",
"destination": "/access-token/2.json"
}
{
"regex": "/access-token/d+.json",
"destination": "/access-token/1.json"
}

最新更新