ember.js - Ember 应用程序已被 CORS 策略阻止
问题描述
我正在尝试使用我的 api,并且我在 ember 应用程序上有一个登录功能,但是当登录操作被触发时,我在下面收到一条消息。我收到此错误的原因是什么?
login:1 Access to fetch at 'https://app-dev.some-url.com.au/api/login' from origin
'http://localhost:4099' has been blocked by CORS policy: Response to preflight request doesn't
pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested
resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch
the resource with CORS disabled.
解决方案
您的 API 服务器未配置为接受来自另一个来源的 Web 应用程序的请求。一些选项:
配置您的 API 以根据浏览器发出
Access-Control-Allow-Origin
的请求提供标头OPTIONS
以进行测试。可能是Access-Control-Allow-Origin: *
您很懒惰或无法提前知道人们的来源。如果不了解 API 的详细信息,很难对此进行更具体的说明。使用 Ember CLI 的API 代理 功能绕过对 CORS 的需求。不过,这仅适用于开发模式。在没有 Ember CLI 的开发服务器的生产环境中,您需要一个类似的解决方案。
推荐阅读
- c# - CS0019 C# 运算符“+”不能应用于“字符串”和“方法组”类型的操作数
- azure - 普罗米修斯。CPU 处理时间总计为 %%
- javascript - 如何在 Next.js 中设置错误和 404 页面?
- awk - 在部分字符是希伯来语的文本中,如何使用正则表达式删除逗号前后的空格?
- python - 可以优化给定的代码吗,我尝试通过引用不同的站点来做到这一点,但它总是向我显示错误
- java - Comparing interface variable without cast to Enum value in java
- python - 将时间序列与 merge_asof 合并并保持最长的时间范围(外连接)
- javascript - 如何在单个文件中导入所有全局 Vue 组件
- excel - 在选定的工作表中循环相同的宏代码
- architecture - 即插即用系统设计?