1

我正在使用 C9 AWS 实例来运行用 ruby​​ on rails 编写的 API REST,并且我正在通过简单的 http 调用从 Ionic 应用程序中消耗资源。当我从 ionic 应用程序发出 http 请求时,服务器会响应以下消息: 如何在 Cloud 9 实例中启用 CORS? 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.

我已经使用rack-cors gem在 rails 中启用了 CORS

4

1 回答 1

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

于 2019-05-21T20:12:09.627 回答