我使用C9 AWS实例来运行在ruby上编写的API REST,并且我使用简单的http调用来消耗Ionic App中的资源。
当我从离子应用程序发出http请求时,服务器响应此消息:
Failed to load https://the_server.vfs.cloud9.us-east-2.amazonaws.com/resource: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access. The response had HTTP status code 404.
如何在Cloud 9实例中启用CORS?
我已经使用 rack-cors gem启用CORS in rails
答案 0 :(得分:0)
对https://the_server.vfs.cloud9.us-east-2.amazonaws.com/resource
的呼叫由代理处理。要允许CORS,您需要直接调用服务器。你可以那样做
通过连接到服务器的IP地址,并打开正确的端口。此处描述:https://docs.aws.amazon.com/cloud9/latest/user-guide/app-preview.html?icmpid=docs_ac9_ide#app-preview-share