【发布时间】:2019-03-10 20:19:41
【问题描述】:
我构建了一个 react 应用程序,并将其部署在 firebase 上。每当用户搜索时,我都会收到此错误。
Failed to load https://food2fork.com/api/search?key=0882376145a8bcae6c3cee&q=fish&count=50: Redirect from
'https://food2fork.com/api/search?key=0882376145a8107c5946c3cee&q=fish&count=50' to
'https://www.food2fork.com/api/search
key=0882376145a8bcae390107c5946c3cee&q=fish&count=50'
has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is
present on the requested resource. Origin 'https://recipe-finder-26e0e.firebaseapp.com' is therefore not allowed access.
由于我是新手,我无法弄清楚如何在 firebase 中启用 CORS,我认为这是问题所在。如果有人能告诉我如何启用 CORS,我将不胜感激。
编辑:源代码链接 --> https://github.com/AdiBev/Recipe-Finder
更新:一开始我不明白 CORS 需要由后端处理。感谢@Ben。 Ayoub 向我解释。
如果它对像我这样遇到同样问题的其他人有所帮助,我发现了一篇很棒的文章,并且在那里提到了一些代理。 链接--->https://gist.github.com/jesperorb/6ca596217c8dfba237744966c2b5ab1e
【问题讨论】:
-
请添加您一直在使用的源代码。不要使用已部署应用程序的链接。 URL 可能会改变,然后这个问题在将来就没有用了。
-
感谢您让我知道该链接。我现在已经添加了源代码。
-
请在问题中添加相关的源代码。不是作为 repo 的链接。
标签: reactjs firebase cors firebase-hosting