我正在编写Angular 6 / Lumen 5.7应用程序
Lumen应用程序在AWS服务器中-> https://api.kendozone.com
Angular应用由github页面托管-> https://v2.kendozone.com
它在本地运行良好,但是当我将其推向生产环境时,我就无法摆脱CORS问题,当我尝试发表登录帖子时,我得到:
Access to fetch at 'https://api.kendozone.com/auth/login' from origin 'https://v2.kendozone.com' 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.kendozone.com/auth/login:1 Failed to load resource: the server responded with a status of 504 (Gateway Timeout)
我已经尝试了几件事:
https://www.codementor.io/chiemelachinedum/steps-to-enable-cors-on-a-lumen-api-backend-e5a0s1ecx
https://gist.github.com/danharper/06d2386f0b826b669552
我现在删除了所有这些脚本,并安装了lumen程序包:
https://github.com/barryvdh/laravel-cors
现在,我什么都没有了...我该怎么办?
答案 0 :(得分:2)
在我看来,最简单的方法是在流明应用程序中定义一个Access-Control-Allow-Origin标头,以允许从https://v2.kendozone.com进行访问。
有关确切的格式和可能性,请参见https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS。
您可能会遇到的问题是,您的cors配置没有在实际请求之前将OPTIONS请求上的那些标头发送回去,或者在到达剥离标头的实际流明端点之前存在重定向。
您在https://www.codementor.io/chiemelachinedum/steps-to-enable-cors-on-a-lumen-api-backend-e5a0s1ecx上发布的方法应该可以使用。请确保为您的所有请求发送回Access-Control- *标头。