Firebase在重定向后避免CORS被移除

Firebase在重定向后避免CORS被移除

问题描述:

我有一个启用CORS的Firebase功能,当我从我的网站使用它的Firebase域调用它时,我已经在Firebase托管中设置了一个自定义域,并且重定向到功能域,尝试它后,我遇到了一些问题,因为CORS头被重定向删除,但我如何在firebase托管域中实现CORS头是一个重定向?Firebase在重定向后避免CORS被移除

的解决方案是使用一个重写代替重定向,这里有文档:

https://firebase.google.com/docs/hosting/functions#directing_hosting_requests_to_your_function

和一个示例firebase.json:

{ 
    "hosting": { 
"public": "public", 

// Add the following rewrites section *within* "hosting" 
"rewrites": [ { 
    "source": "/bigben", "function": "bigben" 
} ] 
    } 
}